Ext.define("Triends.controller.Controller", {

    extend: "Ext.app.Controller",
    config: {
        refs: {
            main: "main",
            ting: "#ting",
            post: "#post",
            account: "#account",
            settings: "#settings"
        },
        control: {
            main: {
				activeitemchange: function(container, value, oldValue, eOpts ) {
					if (value.id == 'account') {
						if (Ext.typeOf(Ext.getCmp('login')) == 'object') {
							Ext.getCmp('titlebar').hide();
						} else {
							Ext.getCmp('titlebar').show();
						}
					} else {
						Ext.getCmp('titlebar').show();
					}
					Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            			url: 'mainpage'
        			}));
				}
            },
            ting: {
            	deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					oldActiveItem.setActiveItem(0);
				},
				activate: function(oldActiveItem, container, newActiveItem, eOpts) {
					var tingopenbtn = Ext.getCmp('tingopenbtn');
					tingopenbtn.show();
				}
            },
            post: {
            	deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					oldActiveItem.setActiveItem(0);
				},
				activate: function(oldActiveItem, container, newActiveItem, eOpts) {
					var tingopenbtn = Ext.getCmp('tingopenbtn');
					tingopenbtn.hide();
				}
            },
            account: {
            	deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					oldActiveItem.setActiveItem(0);
				},
				activate: function(oldActiveItem, container, newActiveItem, eOpts) {
					var tingopenbtn = Ext.getCmp('tingopenbtn');
					tingopenbtn.hide();
				}
            },
            settings: {
            	deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					oldActiveItem.setActiveItem(0);
				},
				activate: function(oldActiveItem, container, newActiveItem, eOpts) {
					var tingopenbtn = Ext.getCmp('tingopenbtn');
					tingopenbtn.hide();
				}
            }
        },
        routes: {
        	'mainpage': 'reset',
            'mainpage/:a/:b' : 'changeView',
            'tinginfo/:a/:b' : 'tinginfoview',  //'tinginfo/account/42'
            'otherinfo/:a/:b/:c' : 'otherinfoview', //'otherinfo/account/ID
 			'tingmodify/:a' : 'tingmodifyview'	
            }
    },
    reset: function() {
    	this.getMain().getActiveItem().setActiveItem(0);
    },
	changeView: function(a, b) {
    	this.getMain().setActiveItem(Ext.getCmp(a));
    	Ext.getCmp(a).setActiveItem(Ext.getCmp(b));
    },
    tinginfoview: function(a, b) {
    	var tingnum = b;
    	var tinginfoStore = Ext.getStore('tinginfoStore'+tingnum);
    	var hostRecord = tinginfoStore.getAt(0);	
		
		var activetab = Ext.getCmp(a);
		
		var tinginfo = Ext.create('Triends.view.Tinginfo');
		
		var hostimg = Ext.getCmp('hostimg');
		hostimg.setSrc('https://graph.facebook.com/'+ hostRecord.getData().ID  +'/picture');
		
 		var tingtitlepanel = Ext.getCmp("tingtitlepanel");
 		var tinginfotheme = Ext.getCmp('tinginfotheme');
 		var tingtimepanel = Ext.getCmp("tingtimepanel");
 		var hostpanel = Ext.getCmp("hostpanel");
 		var tingcontentpanel = Ext.getCmp("tingcontentpanel");
 		tingtitlepanel.setData(hostRecord.getData());
 		tinginfotheme.setSrc('resource/images/'+hostRecord.getData().THEME+'.png');
 		tingtimepanel.setData(hostRecord.getData());
 		hostpanel.setData(hostRecord.getData());
 		tingcontentpanel.setData(hostRecord.getData());
		
 		
		var AttendeeStore = Ext.getStore('AttendeeStore'+tingnum);
		var TingCommentStore = Ext.getStore('TingCommentStore'+tingnum);
		var attendeelistpanel = Ext.getCmp('attendeelistpanel');
		attendeelistpanel.setStore(AttendeeStore);
		attendeelistpanel.refresh();
		
		var TingComment = Ext.getCmp('tingcomment');
		TingComment.setStore(TingCommentStore);
		TingComment.refresh();
		
		var tingjoinbtn = Ext.getCmp("tingjoinbtn");
        var tingjcancelbtn = Ext.getCmp("tingjoincancelbtn");
	    var tingdelbtn = Ext.getCmp("tingdeletebtn");
	    var tingmdfbtn = Ext.getCmp("tingmodifybtn");
		var userid = Ext.getStore("UserStore").getAt(0).data.ID;
		
	    if (hostRecord.data.ID == userid) {
			
			tingjoinbtn.setHidden(true);
		    tingjcancelbtn.setHidden(true);
		    tingdelbtn.setHidden(false);
		    tingmdfbtn.setHidden(false);
	    } else  {
	    	var joincheck = 0;
			AttendeeStore.each( function(model) {
				if (model.data.ID == userid) {
					joincheck++;
				}
			});
			
			if (joincheck == 0) {
		    	tingdelbtn.setHidden(true);
		        tingmdfbtn.setHidden(true);
		        tingjoinbtn.setHidden(false);
		        tingjcancelbtn.setHidden(true);
		    } else {
			    tingdelbtn.setHidden(true);
		       	tingmdfbtn.setHidden(true);
		       	tingjoinbtn.setHidden(true);
		       	tingjcancelbtn.setHidden(false);
		    }
		}
		activetab.add(tinginfo);
		activetab.setActiveItem(tinginfo);
    },
    tingmodifyview: function(a) {
    	var activetab = Ext.getCmp(a);
    	
    	var tingmodify = Ext.create('Triends.view.TingModify');
    	
		var tingmdftitle = Ext.getCmp("tingmdftitle");
		var tingmdftheme = Ext.getCmp("tingmdftheme");
		var tingmdfdate = Ext.getCmp("tingmdfdate");
		var tingmdfampm = Ext.getCmp("tingmdfampm");
		var tingmdfhour = Ext.getCmp("tingmdfhour");
		var tingmdfminute = Ext.getCmp("tingmdfminute");
		var tingmdfcontent = Ext.getCmp("tingmdfcontent");
		var mdfthemeimage = Ext.getCmp('mdfthemeimage');
				
		var tinginfoData = Ext.getCmp("hostpanel").getData();
		Ext.getCmp('tingmodify').setData(tinginfoData);

		var num = tinginfoData.NUMBER;
		var tingtitledata = tinginfoData.TITLE;
							
		var tingthemedata = tinginfoData.THEME;
		var tingdatedata = new Date(tinginfoData.STARTDATE);
		var tingtimedata = tinginfoData.STARTTIME;
		var tingampmdata;
		var tinghourdata = tingtimedata.substring(0,2);
		var tingminutedata = tingtimedata.substring(3);
		if(tinghourdata > 12){
			tinghourdata = tinghourdata - 12;
			tingampmdata = 'PM';
		}else{
			tingampmdata = 'AM';
		}
		var tingcontentdata = tinginfoData.CONTENT;
					
		if (tingtitledata.match("&nbsp;") != null){
			tingtitledata = tingtitledata.replace(/&nbsp;/gi, " "); /*/gi를 써서 전체 문자열을 바꿔준다 */
		}
		tingmdftitle.setValue(tingtitledata);
		Ext.getCmp('tingmdftitlecount').setHtml(tingmdftitle.getValue().length+'/50');
		tingmdftheme.setValue(tingthemedata);
		mdfthemeimage.setSrc('resource/images/'+tingthemedata+'.png');
		tingmdfdate.setValue(tingdatedata);
		tingmdfampm.setValue(tingampmdata);
		tingmdfhour.setValue(tinghourdata);
		tingmdfminute.setValue(tingminutedata);
		if (tingcontentdata.match("<br>") != null || tingcontentdata.match("&nbsp;") != null){
			tingcontentdata = tingcontentdata.replace(/&nbsp;/gi, " "); /*/gi를 써서 전체 문자열을 바꿔준다 */
			tingcontentdata = tingcontentdata.replace(/<br>/gi, "\n");
		}								
		tingmdfcontent.setValue(tingcontentdata);
		Ext.getCmp('tingmdfcontentcount').setHtml(tingmdfcontent.getValue().length+'/250');
			
		activetab.add(tingmodify);
        activetab.setActiveItem(tingmodify);
    },
    otherinfoview: function(a, b, c) {
    	
    	var activetab = Ext.getCmp(a);
    	var otherid = b;
    	
    	var othersStore = Ext.getStore('OthersStore'+otherid);
    	var otherHOSTtingStore = Ext.getStore('otherHOSTtingStore'+otherid);
		var otherATTENDtingstore = Ext.getStore('otherATTENDtingStore'+otherid);
								
  		var otherinfo = Ext.create('Triends.view.Othersinfo');

  		// join버튼이랑 , modify버튼 같이 생각하기.
  		if (c == 'can') {
  			Ext.getCmp('cacaopanel').show();
  		}
  		
  		var FBbutton = Ext.getCmp('FBbutton');
  		FBbutton.setHtml("<a id= 'moveFB' href='https://m.facebook.com/" + otherid +"'>Go to Facebook</a>");//	
		var otherimg = Ext.getCmp('otherimg');
        otherimg.setHtml("<img src='https://graph.facebook.com/"+otherid+"/picture'>");
        var otherinfoview = Ext.getCmp('otherinfoview');
        otherinfoview.setStore(othersStore);
        var otherintroview = Ext.getCmp('otherintroview');        
        otherintroview.setStore(othersStore);
        var otherinfocacao = Ext.getCmp('otherinfocacao');
        otherinfocacao.setStore(othersStore);
        var otherHOSTting = Ext.getCmp('otherhosttingview');
        otherHOSTting.setStore(otherHOSTtingStore);
        var otherATTENDting = Ext.getCmp('otherattendtingview');
        otherATTENDting.setStore(otherATTENDtingstore);
		
        activetab.add(otherinfo);
        activetab.setActiveItem(otherinfo);
        
    }
});

Ext.define('Triends.view.AgreementConfirm', {
	extend: 'Ext.Panel',
	xtype: 'agrmtconfirm',
	id: 'agrmtconfirm',
	config: {
    	modal: true,
    	top: '10%',
    	left: '50%',
    	layout: 'vbox',
    	style: 'margin-left:-150px',
		hideOnMaskTap: true,
		width: 300,
		height: 350,
		listeners: {
			hide: function() {
				this.destroy();
			}
		},
    	items: [
    	{
 	 		xtype: 'panel',
 	 		docked: 'top',
 	 		style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
 	 		items:[
 	 			{
 	 				xtype: 'panel',
 	 				style: 'margin-top:-2px',
 	 				html: "<div valign='center' align='center'><font size='1'><b>이용약관에 대한 동의여부를 선택해주세요</b></font></div>"
 	 			}]
 	 	},
    	{
    		xtype: 'panel',
    		id: 'agreementpanel',
    		scrollable: true,
    		width: '100%',
    		padding: 10,
    		height: 280
    	},
    	{
    		xtype: 'panel',
    		docked: 'bottom',
    		layout: 'hbox',
    		items:[{
	    		xtype: 'button',
	    		flex: 1,
	    		ui: 'action-small',
	    		height: 35,
	    		text: '동의',
	    		handler: function() {
	    				Ext.getCmp('agrmtconfirm').destroy();
			        	FB.login(function(response) {
			        		Ext.Viewport.setMasked({
								xtype: 'loadmask',
								message: '잠시 기다려 주세요.',
								indicator: true
							});	
						FB.api('/me', function(response) {
							Ext.data.JsonP.request({
	            				url: 'http://itscreater.cafe24.com/Triends/Joincheck.jsp',
	            				params: {id:response.id},
	            				callbackKey: 'callback',
	            				success: function(result) {
	            					if(result.message == "Good") {
	            						Ext.getCmp('join').setData({
	            							ID : response.id,
	            							Name: response.name,
	            							Email: response.email,
	            							Age: response.birthday,
	            							Gender: response.gender
	            						});
	            						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            							url: 'mainpage/account/join'
		        						}));
		        						Ext.Viewport.setMasked(false);
	        		        						
	            					} else if (result.message == "Bad") {
	            						Ext.Viewport.setMasked(false);
	            						FB.logout();
	            						Ext.Msg.alert('알림', '이미 가입되어 있습니다', Ext.emptyFn);
	            					}
	            				},
	            				failure: function(result) {
	            					Ext.Viewport.setMasked(false);
	            					Ext.Msg.alert('알림', '서버 실행 오류:', Ext.emptyFn);
	            				}
	            			});	
						});	
	            	}, {scope: 'email, user_birthday'});
	
	    		}	    		
	    	},
	    	{
    		xtype: 'button',
    		flex: 1,
    		ui: 'small',
    		height: 35,
    		text: '취소',
    		handler: function() {
    			Ext.getCmp('agrmtconfirm').destroy();
    		}
    	}]
    	}]
	}
});

Ext.define("Triends.Model.AttendeeList",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"ID", "Name", "Email", "Age", "Gender", "Introduction", "Cacao"
		]
	}
});

Ext.define('Triends.view.AttendeeList', {
	extend: 'Ext.Panel',
	xtype: 'attendeelist',
	id: 'attendeelist',
	config: {
		layout: 'vbox',
		style: 'border-top:1px #CBCAC7 solid;margin-bottom:10px',
		minHeight: 120,
		items: [{
		    	xtype: 'panel',
		    	style: 'margin-top:15px;margin-left:10px',
		    	html: "<p style='margin-left:10px'><font size='4'><b>Attendee</b></font></p>"
			},
			{
				xtype: 'panel',
				style: {'margin':'5px'},
				items:[{
						xtype: 'list',
						width: '98.2%',
						id: 'attendeelistpanel',
						pressedCls: "x-item-selected",
						selectedCls: "",
						pressedDelay: 50,
						style: 'background:white;margin-left:5px',
						scrollable: false,
						itemTpl:
								"<table>"+
									"<tr>" +
										"<td rowspan='2' align='center' valign='center' width=50 style='word-break:break-all'><img src='https://graph.facebook.com/{ID}/picture' width='48px' height='48px'></td>" +
										"<td valign='center'><p style='margin-left:20px'><font size='4'>{Name}</font></p></td>" +
									 "</tr>" +
									"<tr>" +
										"<td></td>" +
									"</tr>"+
								"</table>",
				    	listeners: {
	    	   				itemtap: function(list, index, target, model, e, eOpts) {
		    					var otherid = model.getData().ID;
		    					var cacaocheck;
											if (Ext.getCmp('tingjoinbtn').isHidden() == false) {
  												cacaocheck = 'cannot';
  											} else {
  												cacaocheck = 'can'
  											}
								openOtherinfo(otherid, cacaocheck)
		    	  		}
					}
				}]
		}]
  	}
});
	
 Ext.define('Triends.view.HelpPage', {
 	extend: 'Ext.Panel',
 	xtype: 'helppage',
 	id: 'helppage',
 	alias: 'helppage',
 	config: {
 		fullscreen: true,
 		layout: 'vbox',
 		style: 'background: white',
 		scrollable: true,
 		items: [{
	   		xtype: 'panel',
	   		docked: 'top',
	   		height: 30,
	   		style: {'padding-top':'3px','padding-left':'27px','background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))'},
	   		html: '<b>Help</b>'
	   	},
	   	{
	   		xtype: 'panel',
	   		padding: 30,
	   		items: [{
	   			xtype: 'panel',
	 			style: 'white-space:pre-line;background:white',
	 			html: '<font size="3"><font size="5">1.</font> <b>“Ting”</b>은 Triends 서비스를 통해서 여행자들이 만나는 모임을 의미합니다.<br><br>' +
	 				'-&nbsp;우측 상단에 있는 버튼을 통해 새로운 Ting을 만들 수 있습니다.<br>' +
	 				'-&nbsp;검색 창을 통해 개설되어 있는 Ting을 찾아 참여할 수 있습니다.<br><br><br><br>' +
	 				'<font size="5">2.</font> <b>“Post”</b> 탭에서 이용자들은 게시글을 작성, 열람할 수 있습니다.<br><br>' +
	 				'-&nbsp;게시판은 지역기반 게시판과 일반 게시판, 두 가지 형태로 제공됩니다.<br><br><br><br>' +
	 				'<font size="5">3.</font> <b>“Account”</b> 탭에서는 이용자의 Facebook 계정을 기반으로 한 개인 정보를 확인할 수 있습니다.<br><br>' +
	 				'-&nbsp다른 사용자와 메시지를 주고 받을 수 있고, 자신이 참여하고 있는 Ting에 대한 정보를 확인할 수 있습니다.<br><br><br><br>' +
	 				'<font size="5">4.</font> 기타 서비스 이용 시 문의사항은 <font size="4"><u>info@triends.co.kr</u></font>로 해주시기 바랍니다.</font>'
	   		}]
	   	}]
 	}
 });
 
 Ext.define('Triends.view.Join', {
	extend: 'Ext.Panel',
	xtype: 'join',
	id: 'join',
	config: {
	    styleHtmlContent: true,
	    scrollable: false,
    	items: [
    	{
    		xtype: 'fieldset',
    		instructions: '같은 Ting(모임)의 멤버들과 연락하기 위한 목적으로만 사용됩니다.',
	    	items: [{
    			xtype: 'textfield',
    			style: 'border:3px inset',
	    		id : 'joincacao',
    	        label: '카카오톡  ID',
    	        maxLength: 200
        	}]
    	},
    	{
    		xtype: 'fieldset',
    		instructions: '여행기간을 입력해주세요',
    		items:[
        	{
				xtype: 'datepickerfield',
				label: '여행 시작일',
				style: 'border:3px inset',
				id: 'travelstart',
				dateFormat: "Y-m-d",
				picker: {
						hideOnMaskTap: true,
						yearFrom: 2012,
						yearTo: 2013,
						slotOrder: ['year', 'month', 'day'],
						useTitles: true
				}
			 },
			 {
				xtype: 'datepickerfield',
				label: '여행 종료일',
				style: 'border:3px inset',
				id: 'travelend',
				dateFormat: "Y-m-d",
				picker: {
						hideOnMaskTap: true,
						yearFrom: 2012,
						yearTo: 2013,
						slotOrder: ['year', 'month', 'day'],
						useTitles: true
				}
 			 }]
    	},
    	{
			xtype: 'button',
			text: 'Create a Account',
			handler: function(){
				var joindata = Ext.getCmp('join').getData();
				var cacao = Ext.getCmp('joincacao').getValue();
				var travelstart = Ext.getCmp('travelstart').getFormattedValue();
				var travelend = Ext.getCmp('travelend').getFormattedValue();
 							
 				Ext.data.JsonP.request({
   					url: 'http://itscreater.cafe24.com/Triends/Join.jsp',
   					params: {
   						id: joindata.ID,
   						name:joindata.Name, 
   						email:joindata.Email,
   						age:joindata.Age,
   						gender:joindata.Gender,
   						cacao:cacao,
   						travelstart: travelstart,
   						travelend: travelend
   					},
          			callbackKey: 'callback',
          			success: function(result) {
          				
            				var UserStore = Ext.getStore('UserStore');
							UserStore.getProxy().setExtraParams({id: joindata.ID});
            				UserStore.load({
				        				callback: function(records, operation, success) {
				        					var userid = UserStore.getAt(0).data.ID;
        									var userimg = Ext.getCmp('userimg');
        									userimg.setHtml("<img src='https://graph.facebook.com/"+userid+"/picture'>");
			        					
        									var userHOSTtingStore = Ext.getStore('userHOSTtingstore');
											userHOSTtingStore.getProxy().setExtraParams({id: userid});
											userHOSTtingStore.load({
												callback: function() {
													var titlebar = Ext.getCmp('titlebar');
													titlebar.show();
													var logincmp = Ext.getCmp('login');
        		        							logincmp.destroy();
        		        							Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            											url: 'mainpage'
            										}));
													var userATTENDtingStore = Ext.getStore('userATTENDtingstore');		
													userATTENDtingStore.getProxy().setExtraParams({id: userid});
													userATTENDtingStore.load();
												}
											});
											var msgStore = Ext.getStore('msgstore');
								 				msgStore.getProxy().setExtraParams({id: userid});
 												msgStore.load();
				        				}
            				});
           			}
     	 		});
     	 		Ext.Msg.alert("", "Triends에 오신 것을 환영합니다.");
			}
 		}]
	}
});

//PostingLocation에서 fieldset으로 사용하기 위함

Ext.define("Triends.LocationModel",{
	extend: "Ext.data.Model",
	id: 'locationmodel',
	config: {
		fields: [
			{name: 'CONTINENT', type: 'string'},
			{name: 'NATION', type: 'string'}
		]
	}
});

var cStore = Ext.create("Ext.data.Store",{
	model: "Triends.LocationModel",
	proxy: {
		type: "jsonp",
		url: 'http://itscreater.cafe24.com/Triends/LocationC.jsp',
		callbackkey: 'callback',
		reader: {
			type: "json"
		}
	},
	sorters:[
		{property: 'CONTINENT', direction: 'ASC'}
	],
	autoLoad: true
});

var nStore = Ext.create("Ext.data.Store",{
	model: "Triends.LocationModel",
	sorters:[
		{property: 'NATION', direction: 'ASC'}
	]
});

Ext.define("Triends.view.LocationField1",{
	extend: 'Ext.form.FieldSet',
	xtype: 'locationfield1',
	id: 'locationfield1',
	alias: 'locationfield1',
	config:{
		title: 'Location',
		items:[
 				{
	 				xtype: 'selectfield',
	 				label: "대륙",
	 				name: 'continent',
	 				id: 'continent',
	 				style: 'border:3px inset',
	 				store: cStore,
	 				usePicker: false,
	 				displayField: 'CONTINENT',
	 				valueField: 'CONTINENT',	 				
	 				listeners: 
						{
						    change: function(selectbox,newValue,oldValue)
						    {						    	
						            Ext.data.JsonP.request({
					 					url: 'http://itscreater.cafe24.com/Triends/LocationN.jsp',
					 					params: {cValue: Ext.getCmp("continent").getValue()},
					 					callbackkey: 'callback',
					 					success: function(result){					 						
											nStore.setData(result);					 						
					 					}
 									});						       
						    }
						}   
	 			},
 				{
	 				xtype: 'selectfield',
	 				label: '국가',
	 				name: 'nation',
	 				style: 'border:3px inset',
	 				id: 'nation',
	 				store: nStore,
	 				usePicker: false,
	 				displayField: 'NATION',
	 				valueField: 'NATION'
 				}
 			]
		}
})

//LocationOverlay에서 fieldset으로 활용하기 위함!

Ext.define("Triends.LocationModel",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			{name: 'CONTINENT', type: 'string'},
			{name: 'NATION', type: 'string'}
		]
	}
});

var cStore2 = Ext.create("Ext.data.Store",{ /* LocationField1과 구분하기 위해 2로 다시 명명 */
	model: "Triends.LocationModel",
	proxy: {
		type: "jsonp",
		url: 'http://itscreater.cafe24.com/Triends/LocationC.jsp',
		callbackkey: 'callback',
		reader: {
			type: "json"
		}
	},
	sorters:[
		{property: 'CONTINENT', direction: 'ASC'}
	],
	autoLoad: true
});

var nStore2 = Ext.create("Ext.data.Store",{
	model: "Triends.LocationModel",
	sorters:[
		{property: 'NATION', direction: 'ASC'}
	]
});


Ext.define("Triends.view.LocationField2",{
	extend: 'Ext.form.FieldSet',
	xtype: 'locationfield2',
	id: 'locationfield2',
	alias: 'locationfield2',
	config:{
		width: 265,
		items:[
 				{
	 				xtype: 'selectfield',
	 				label: "대륙",
	 				name: 'continent',
	 				id: 'continent2',
	 				store: cStore2,
	 				usePicker: false,
	 				labelWidth: 100,
	 				displayField: 'CONTINENT',
	 				valueField: 'CONTINENT',	 				
	 				listeners: 
						{
						    change: function(selectbox,newValue,oldValue)
						    {						    	
						            Ext.data.JsonP.request({
					 					url: 'http://itscreater.cafe24.com/Triends/LocationN.jsp',
					 					params: {cValue: Ext.getCmp("continent2").getValue()},
					 					callbackkey: 'callback',
					 					success: function(result){					 						
											nStore2.setData(result);					 						
					 					}
 									});						        
						    }
						}   
	 			},
 				{
	 				xtype: 'selectfield',
	 				label: '국가',
	 				name: 'nation',
	 				id: 'nation2',
	 				labelWidth: 100,
	 				store: nStore2,
	 				usePicker: false,
	 				displayField: 'NATION',
	 				valueField: 'NATION'
 				}
 			]
		}
})

//PostLocationModify에서 fieldset으로 활용하기 위함!

Ext.define("Triends.LocationModel",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			{name: 'CONTINENT', type: 'string'},
			{name: 'NATION', type: 'string'}
		]
	}
});

var cStore3 = Ext.create("Ext.data.Store",{ /* LocationField1과 구분하기 위해 2로 다시 명명 */
	model: "Triends.LocationModel",
	proxy: {
		type: "jsonp",
		url: 'http://itscreater.cafe24.com/Triends/LocationC.jsp',
		callbackkey: 'callback',
		reader: {
			type: "json"
		}
	},
	sorters:[
		{property: 'CONTINENT', direction: 'ASC'}
	],
	autoLoad: true
});

var nStore3 = Ext.create("Ext.data.Store",{
	model: "Triends.LocationModel",
	sorters:[
		{property: 'NATION', direction: 'ASC'}
	]
});


Ext.define("Triends.view.LocationField3",{
	extend: 'Ext.form.FieldSet',
	xtype: 'locationfield3',
	id: 'locationfield3',
	alias: 'locationfield3',
	config:{
		title: 'Location',
		items:[
 				{
	 				xtype: 'selectfield',
	 				label: "대륙",
	 				name: 'continent',
	 				id: 'continent3',
	 				style: 'border:3px inset',
	 				store: cStore3,
	 				usePicker: false,
	 				displayField: 'CONTINENT',
	 				valueField: 'CONTINENT',	 				
	 				listeners: 
						{
						    change: function(selectbox,newValue,oldValue)
						    {						    	
						            Ext.data.JsonP.request({
					 					url: 'http://itscreater.cafe24.com/Triends/LocationN.jsp',
					 					params: {cValue: Ext.getCmp("continent3").getValue()},
					 					callbackkey: 'callback',
					 					success: function(result){					 						
											nStore3.setData(result);					 						
					 					}
 									});						        
						    }
						}   
	 			},
 				{
	 				xtype: 'selectfield',
	 				label: '국가',
	 				name: 'nation',
	 				id: 'nation3',
	 				style: 'border:3px inset',
	 				store: nStore3,
	 				usePicker: false,
	 				displayField: 'NATION',
	 				valueField: 'NATION'
 				}
 			]
		}
})

Ext.define("Triends.LocationModel",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			{name: 'CONTINENT', type: 'string'},
			{name: 'NATION', type: 'string'}
		]
	}
});

var cStore4 = Ext.create("Ext.data.Store",{ /* LocationField1과 구분하기 위해 2로 다시 명명 */
	model: "Triends.LocationModel",
	proxy: {
		type: "jsonp",
		url: 'http://itscreater.cafe24.com/Triends/LocationC.jsp',
		callbackkey: 'callback',
		reader: {
			type: "json"
		}
	},
	sorters:[
		{property: 'CONTINENT', direction: 'ASC'}
	],
	autoLoad: true
});

var nStore4 = Ext.create("Ext.data.Store",{
	model: "Triends.LocationModel",
	sorters:[
		{property: 'NATION', direction: 'ASC'}
	]
});


Ext.define("Triends.view.LocationField4",{
	extend: 'Ext.form.FieldSet',
	xtype: 'locationfield4',
	id: 'locationfield4',
	alias: 'locationfield4',
	config:{
//		docked: 'top',
		title: 'Location',
		items:[
 				{
	 				xtype: 'selectfield',
	 				label: "대륙",
	 				name: 'continent',
	 				id: 'continent4',
	 				store: cStore4,
	 				usePicker: false,
	 				displayField: 'CONTINENT',
	 				valueField: 'CONTINENT',	 				
	 				listeners: 
						{
						    change: function(selectbox,newValue,oldValue)
						    {						    	
						            Ext.data.JsonP.request({
					 					url: 'http://itscreater.cafe24.com/Triends/LocationN.jsp',
					 					params: {cValue: Ext.getCmp("continent4").getValue()},
					 					callbackkey: 'callback',
					 					success: function(result){					 						
											nStore4.setData(result);					 						
					 					}
 									});						        
						    }
						}   
	 			},
 				{
	 				xtype: 'selectfield',
	 				label: '국가',
	 				name: 'nation',
	 				id: 'nation4',
	 				store: nStore4,
	 				usePicker: false,
	 				displayField: 'NATION',
	 				valueField: 'NATION'
 				}
 			]
		}
})

Ext.define("Triends.view.LocationOverlay",{
	extend: 'Ext.form.Panel',
	requires: 'Triends.view.LocationField2',
	xtype: 'locationoverlay',
	id: 'locationoverlay',
	config:{
		floating: true,
		hideOnMaskTap: true,
		modal: true,
		top: '20%',
    	left: '50%',
    	style: 'margin-left:-155px',
		width: 310,
		height: 210,
		listeners: {
			hide: function() {
				this.destroy();
			}
		},
		items: [
			{
				xtype: 'locationfield2' /* xtype로 바인딩 되려면 Ext.define으로 새 파일을 만들어 줘야 인식한다. */
			},
			{
				xtype: 'panel',
				width: 260,
				layout: 'hbox',
				items: [{
							xtype: 'button',
							ui: 'action',
							flex: 1,
							text: 'Search',
							handler: function(){
								var continent2 = Ext.getCmp("continent2");
								var nation2 = Ext.getCmp("nation2");
								var postLocationStore = Ext.getStore("postlocationstore");
								if (continent2.getValue() != ''){ /* 공백값은 작은 따옴표!! */
										postLocationStore.removeAll();
										postLocationStore.setProxy({
											type: "jsonp",
											url: 'http://itscreater.cafe24.com/Triends/PostLocationList.jsp',
											extraParams: {continent: continent2.getValue(),
														  nation: nation2.getValue()},
											callbackkey: 'callback',
											pageParam: 'pages',
											limitParam: 'rpp',
											reader: {
												type: "json",
												rootProperty: "results",
												totalProperty: "total"
											}
										})
										postLocationStore.loadPage(1);
										localStorage.clear();
										localStorage.setItem("continent", continent2.getValue());
										localStorage.setItem("nation", nation2.getValue());
										continent2.reset();
										nation2.reset();
										
										var locationOverlay = Ext.getCmp("locationoverlay");
										locationOverlay.hide();
										locationOverlay.destroy();
								} else {
									Ext.Msg.alert("알림", "지역을 선택하세요");
								} 					
							}
							
						},
						{
							xtype: 'button',
							flex: 1,
							text: 'Close',
							handler: function(){
								var locationOverlay = Ext.getCmp("locationoverlay");
								locationOverlay.hide();
								locationOverlay.destroy();
						}
					}
				]
			}
					]
	}
});

Ext.define('Triends.view.Login', {
	extend: 'Ext.Panel',
	requires: ['Triends.view.AgreementConfirm'],
	xtype: 'login',
	id: 'login',
	config: {
		fullscreen: true,
		scrollable: true,
		style: 'background:white',
    	width: '100%',
    	showAnimation: 'slideIn',
    	height: '100%',
    	layout: 'vbox',
		items: [
			{
					xtype: 'panel',
					style: {'left':'50%', 'margin-left':'-35%', 'margin-top':'5%'},
					height: '70%',
					width: '70%',
					html: "<img src='resource/images/triendsaccount1.png'>"
			},
			{
			xtype: 'panel',
			layout: 'vbox',
			style: {'margin-top':'10%'},
			items:[
				{
					xtype: 'panel',
					xtype: 'panel',
					style: {'left':'50%', 'margin-left':'-130px'},
					width: '278px',
					html: '<font size="2"><b>클릭 한 번으로 간편하게 로그인하세요</b></font>'
				},
				{
	        	xtype: 'button',
				style: {'left':'50%', 'margin-left':'-139px', 'margin-top':'3px'},
	            name: 'Login',
	           	width: '278px',
		        height: '44px',
	            cls: 'FBlogin',
	            pressedCls: 'pressedlogin',
				handler: function(){
            	
//				var userlat, userlng;
//            	
//            	navigator.geolocation.getCurrentPosition(function(pos){
//            		 userlat = pos.coords.latitude;
//            		 userlng = pos.coords.longitude;
            	
				
            	FB.login(function(response) {
            		Ext.Viewport.setMasked({
								xtype: 'loadmask',
								message: '로그인 중입니다.',
								indicator: true
							});	
					FB.api('/me', function(response) {
						Ext.data.JsonP.request({
            				url: 'http://itscreater.cafe24.com/Triends/Login.jsp',
            				params: {
            					id:response.id,
            					name:response.name,
            					email:response.email, 
            					age:response.age,
            					gender:response.gender
            					// Userlist에서 사용할 부분
            					//userlat:userlat,
            					//userlng:userlng
            				},
            				callbackKey: 'callback',
            				success: function(result) {
            					if(result.message == "Good") {
							    	var UserStore = Ext.getStore('UserStore');
							    	UserStore.getProxy().setExtraParams({id: response.id});
            						UserStore.load({
				        				callback: function(records, operation, success) {
				        					var userid = UserStore.getAt(0).data.ID;
				        					
				        					window.GCM.register("157631774206", "GCM_Event", GCM_Success, GCM_Fail );
        									var userimg = Ext.getCmp('userimg');
        									userimg.setHtml("<img src='https://graph.facebook.com/"+userid+"/picture'>");
			        					
        									var userHOSTtingStore = Ext.getStore('userHOSTtingstore');
											userHOSTtingStore.getProxy().setExtraParams({id: userid});
											userHOSTtingStore.load({
												callback: function() {
													var userATTENDtingStore = Ext.getStore('userATTENDtingstore');		
													userATTENDtingStore.getProxy().setExtraParams({id: userid});
													userATTENDtingStore.load({
														callback: function() {
																var titlebar = Ext.getCmp('titlebar');
																	titlebar.show();
            													var accountcmp = Ext.getCmp('account');
        		        											accountcmp.setActiveItem(1);
        		        											Ext.Viewport.setMasked(false);
        		        										var logincmp = Ext.getCmp('login');
        		        											logincmp.destroy();
														}
													});
												}
											});
				        				}
            						});
            					} else if (result.message == "Bad") {
            						Ext.Viewport.setMasked(false);
            						FB.logout();
            						Ext.Msg.alert('알림', '가입되어있지 않습니다', Ext.emptyFn);
            					}
            				},
            				failure: function(result) {
            					Ext.Viewport.setMasked(false);
            					Ext.Msg.alert('알림', '서버 실행 오류:', Ext.emptyFn);
            				}
            			});	
					});	
            	}, {scope: 'user_birthday'});
            }
			}]
		},
		{
        	xtype: 'panel',
        	style: {'margin-top':'5%'},
        	items: [
        		{
					xtype: 'panel',
					style: {'left':'50%', 'margin-left':'-130px'},
					width: '278px',
					html: '<font size="2"><b>아직 회원이 아니신가요?</b></font>'
				},
        		{
		        	xtype: 'button',
		        	style: {'left':'50%', 'margin-left':'-139px', 'margin-top':'3px'},
		           	width: '278px',
		           	height: '44px',
		            cls: 'FBconnect',
		            pressedCls: 'pressedconnect',
		           	handler: function() {
		           		var agrmtconfirm = Ext.create('Triends.view.AgreementConfirm');
		           		Ext.Viewport.add(agrmtconfirm);
		           		
		           		Ext.data.JsonP.request({
		           			url: 'http://itscreater.cafe24.com/Triends/UserAgreement.jsp',
		           			callbackKey: 'callback',
		           			success: function(result){
		           				var agreementpanel = Ext.getCmp('agreementpanel');
		           				agreementpanel.setHtml('<font size="2">'+result.Agree+'</font>');
		           			}
		           		})
	           	}
           	}]
		},
		{
			xtype: 'panel',
			docked: 'bottom',
			items:[
				{
			        	xtype: 'button',
			            name: 'Logout',
			            text: 'Logout',
			            width: '184px',
			            ui: 'round',
			            handler: function(){
			            					
			        		var UserStore = Ext.getStore('UserStore');
			        		UserStore.getProxy().setExtraParams({id: '100001772264931'});  //response.id
			        											//이웅 100001772264931 용진 100002448321152
			        		UserStore.load({
			        				callback: function(records, operation, success) {
			        					
			        					var userid = UserStore.getAt(0).data.ID;
			        					var userimg = Ext.getCmp('userimg');
			        					userimg.setHtml("<img src='https://graph.facebook.com/"+userid+"/picture'>");
			        					
			        					var userHOSTtingStore = Ext.getStore('userHOSTtingstore');
										userHOSTtingStore.getProxy().setExtraParams({id: userid});
										userHOSTtingStore.load({
											callback: function() {
												var userATTENDtingStore = Ext.getStore('userATTENDtingstore');		
												userATTENDtingStore.getProxy().setExtraParams({id: userid});
												userATTENDtingStore.load({
													callback: function() {
			   			   								var msgStore = Ext.getStore('msgstore');
			            									msgStore.getProxy().setExtraParams({id: userid});
			            									msgStore.load({
			            										callback: function() {
			            											var accountcmp = Ext.getCmp('account');
			        		        									accountcmp.setActiveItem(1);
			        		        									var titlebar = Ext.getCmp('titlebar');
																			titlebar.show();
			        		        								var logincmp = Ext.getCmp('login');
        		        											logincmp.destroy();
			            										}
			            									});
													}
												});
											}
										});
			        				}
			        		});
		            }
				}]
		
		}]
	}
});

function
				GCM_Event(e)
				{
				
				  switch( e.event )
				  {
				  case 'registered':
				  	var UserStore = Ext.getStore('UserStore');
			      	var userid = UserStore.getAt(0).data.ID;
				    // the definition of the e variable is json return defined in GCMReceiver.java
				    // In my case on registered I have EVENT and REGID defined
				    Ext.data.JsonP.request({
				    	url: 'http://itscreater.cafe24.com/Triends/gcminsert.jsp',
				      	params: {
				      		id: userid,
				      		regid: e.regid
				      	},
				      	callbackKey: 'callback'
				      })
				
				    break;
				
				  default:
				    alert('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
				
				    break;
				  }
				}
				
				function
				GCM_Success(e)
				{
				  alert('<li>GCM_Success -> We have successfully registered and called the GCM plugin, waiting for GCM_Event:registered -> REGID back from Google</li>');
				
				}
				
				function
				GCM_Fail(e)
				{
				  alert('<li>GCM_Fail -> GCM plugin failed to register</li>');
				
				  alert('<li>GCM_Fail -> ' + e.msg + '</li>');
				
				}


function addviews() {
            		Ext.getCmp('ting').insert(1, {xtype: 'tingopen'});
            		Ext.getCmp('account').insert(2, {xtype: 'join'});
            		Ext.getCmp('account').insert(3, {xtype: 'mymsg'});
            		Ext.getCmp('account').insert(4, {xtype: 'msginfo'});
            		Ext.getCmp('account').insert(5, {xtype: 'infomodify'});
            		Ext.getCmp('settings').insert(1, {xtype: 'versionpage'});
            		Ext.getCmp('settings').insert(2, {xtype: 'noticelist'});
            		Ext.getCmp('settings').insert(3, {xtype: 'noticeinfo'});
            		Ext.getCmp('settings').insert(4, {xtype: 'helppage'});
            		Ext.getCmp('settings').insert(5, {xtype: 'questionpage'})
            		Ext.getCmp('settings').insert(5, {xtype: 'pushpage'});
            		}

Ext.define('Triends.view.MainPage', {
    	extend: 'Ext.TabPanel',
    	id: 'main',
    	xtype: 'main',
    	alias: 'mainpage',
    	requires: ['Ext.Button', 'Ext.TitleBar', 'Triends.view.Tinglist',
    				'Triends.view.TingOpen', 'Triends.view.PostMain', 
    				'Triends.view.PostingNormal','Triends.view.Postinfo', 'Triends.view.PostNormalModify',
    				'Triends.view.Login',
    				'Triends.view.Userinfo', 'Triends.view.Join', 'Triends.view.Mymessage',
    				'Triends.view.Mymessageinfo','Triends.view.UserinfoModify',
    				'Triends.view.Settings', 'Triends.view.VersionPage', 'Triends.view.Noticelist',
    				'Triends.view.Noticeinfo', 'Triends.view.HelpPage', 'Triends.view.QuestionPage'],
    	config: {
    		fullscreen: true,
    		hidden:true,
    		layout: 'card',
    		showAnimation: 'slideIn',
            tabBarPosition : 'bottom',
            listeners: {
            	initialize: function() {
            		setTimeout("addviews()", 500);
            	}
            },
    		items: [
    				{
		    	    	xtype: 'titlebar',
		    	    	docked: 'top',
		    	    	id: 'titlebar',
		    	    	height: '40px',
		    	    	title: "<p class='triendstitle'>Triends</p>",
//		    	    	style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#16374F), to(#131426))'},
		    	    	items: [
	    	    		{
	    	    			xtype: 'button',
	    	    			id: 'tingopenbtn',
	    	    			align: 'right',
	    	    			iconCls: 'team',
	    	    			iconMask: true,
	    	    			handler: function(){
	    	    				
	        					try {
	        						var userid = Ext.getStore("UserStore").getAt(0).data.ID;
									Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            						url: 'mainpage/ting/tingopen'
	        						}));
	        					} catch(e){
	        						Ext.Msg.alert("","로그인이 필요합니다");
	        					} 
	    	    			}
	    	    		}]
    				},
		    		{
		    			title: 'Ting',
		    			iconCls: 'search',
		    			xtype: 'panel',
		    			id: 'ting',
		    			layout: 'card',
		    			showAnimation: 'slideIn',
		    			items: [{
			    			xtype: 'tinglist'
//			    		},
//			    		{
//			    			xtype: 'tingopen'
			    		}]
		    		},
		    		{
		    			title: 'Post',
		    			iconCls: 'compose',
		    			id: 'post',
		    			xtype: 'panel',
		    			layout: 'card',
		    			showAnimation: 'slideIn',
		    			items: [
		    			{
		    				xtype: 'postnormallist'
		    			},
		    			{
//		    				xtype: 'postinglocation'
		    			},
		    			{
//		    				xtype: 'postingnormal'
//		    			},
//		    			{
//		    				xtype: 'postinfo'
//		    			},
//		    			{
//		    				xtype: 'postnormalmodify'
//		    			},
//		    			{
//		    				xtype: 'postlocationmodify'
		    			}]
		    		},
		    		{
		    			title: 'Account',
		    			iconCls: 'user',
		    			xtype: 'panel',
		    			id: 'account',
		    			layout: 'card',
		    			showAnimation: 'slideIn',
		    			items: [{
		    				xtype: 'login'
		    			},{
		    				xtype: 'userinfo'
		    			},{
//		    				xtype: 'join'
		    			},{
//		    				xtype: 'mymsg'
		    			},{
//		    				xtype: 'msginfo'
		    			},{
//		    				xtype: 'infomodify'
		    			}]
					},
					{
						title: 'Info',
						iconCls: 'info',
						iconMask: true,
						xtype: 'panel',
						id: 'settings',
						showAnimation: 'slideIn',
						layout: 'card',
						items: [{
							xtype: 'settingslist'
						},{
//							xtype: 'versionpage'
						},{
//							xtype: 'noticelist'
						},{
//							xtype: 'noticeinfo'
						},{
//							xtype: 'helppage'							
						},{
//							xtype: 'questionpage'							
						}]
					
			}]
    	}
});
    
// TingOpen에서 쓰는 MapOverlay!!

		var geocoder;
		geocoder = new google.maps.Geocoder();

		var latlng = new google.maps.LatLng(37.55575425229087, 126.93629264831543);
		var selectedLocation, lat, lng;
		
		
		Ext.define("Triends.Map2",{
			extend: "Ext.Map",
			xtype: "map2",
			id: "map2",
			config:{
				width:300,
				mapOptions: {
					center: latlng,
					zoom: 11,
					zoomControl: true,
					mapTypeId: google.maps.MapTypeId.ROADMAP,
					streetViewControl: false,
					mapTypeControl: false,
					disableDoubleClickZoom: true
				},
				listeners: {
					maprender: function(comp, map){
						var marker = new google.maps.Marker({map:map, icon: 'resource/images/mappin1.png'});
						
						google.maps.event.addListener(map, 'dblclick', function(event){ // map은 항상 map, click이 아니라 mousedown 이벤트다!
							selectedLocation = event.latLng;
							marker.setPosition(selectedLocation);
							lat = selectedLocation.lat();
							lng = selectedLocation.lng();
						});	
					}
				}
			}
		});
		
		function showAddress(){
			 var address = Ext.getCmp("map2search").getValue();
       			 geocoder.geocode( { 'address': address}, function(results, status) {
          			if (status == google.maps.GeocoderStatus.OK) {
          				var map2 = Ext.getCmp("map2")
            			map2.setMapCenter(results[0].geometry.location);
          			} else {
            			alert('Geocode was not successful for the following reason: ' + status);
          			}
        		});
      	}
		
      	
Ext.define('Triends.view.MapOverlay',{ // TingOpen에서 requires로 잡아주고 여기에서는 만들어 놓는다.
	extend: 'Ext.Panel',
	id: 'mapoverlay',
	config: {		
		layout: 'fit',
		floating: true,
		hideOnMaskTap: true,
		listeners: {
			hide: function() {
				this.destroy();
			}
		},
		modal: true,
		centered: true,
		width: 310,
		height: 400,
		items: [
				{
					xtype: 'toolbar',
					width: 300,
					docked: 'top',
					items: [{
		           		xtype: 'searchfield',
		           		id: 'map2search',
		           		width: 200,
		            	placeHolder: "Input city name",
		            	autocomplete: true,
		            	autoCreateField: true
					},
					{
		            	xtype: 'button',
		            	iconCls: 'search',
		            	iconMask: true,
		            	handler: function(){
		            		showAddress();
	            		}
	            	}]
				},
				{
		 	 		xtype: 'panel',
		 	 		docked: 'top',
		 	 		style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
		 	 		items:[
		 	 			{
		 	 				xtype: 'panel',
		 	 				style: 'margin-top:-2px',
		 	 				html: "<div valign='center' align='center'><font size='1'><b>더블클릭으로 위치를 선택하세요</b></font></div>"
		 	 			}]
 	 			},
				{
					xtype: 'panel',
					docked: 'bottom',
					layout: 'hbox',
					items: [
					{
						xtype: 'button',				
						flex: 1,
						text: '선택완료',
						handler: function(){
							if(selectedLocation == null){
									Ext.Msg.alert("","위치를 선택하세요");
									return;
							}else{
								var mapOverlay = Ext.getCmp("mapoverlay");
								localStorage.setItem("lat", lat);
								localStorage.setItem("lng", lng);
								Ext.Msg.alert("","위치가 선택되었습니다");
								mapOverlay.destroy();
							}
						}
					},
					{
						xtype: 'button',
						flex: 1,
						text: '닫기',
						handler: function(){
							var mapOverlay = Ext.getCmp("mapoverlay");
							mapOverlay.destroy();
						}
					}
					]
				}
				]
		}
});

// TingOpen에서 쓰는 MapOverlay!!

		var geocoder;
		geocoder = new google.maps.Geocoder();

		var latlng = new google.maps.LatLng(37.55575425229087, 126.93629264831543);
		var selectedLocation, lat, lng;
		
		
		Ext.define("Triends.Map2",{
			extend: "Ext.Map",
			xtype: "map2",
			id: "map2",
			config:{
				width:300,
				mapOptions: {
					center: latlng,
					zoom: 11,
					zoomControl: true,
					mapTypeId: google.maps.MapTypeId.ROADMAP,
					streetViewControl: false,
					mapTypeControl: false,
					disableDoubleClickZoom: true
				},
				listeners: {
					maprender: function(comp, map){
						var marker = new google.maps.Marker({map:map, icon: 'resource/images/mappin1.png'});
						
						google.maps.event.addListener(map, 'dblclick', function(event){ // map은 항상 map, click이 아니라 mousedown 이벤트다!
							selectedLocation = event.latLng;
							marker.setPosition(selectedLocation);
							lat = selectedLocation.lat();
							lng = selectedLocation.lng();
						});	
					}
				}
			}
		});
		
		function showAddress(){
			 var address = Ext.getCmp("map2search").getValue();
       			 geocoder.geocode( { 'address': address}, function(results, status) {
          			if (status == google.maps.GeocoderStatus.OK) {
          				var map2 = Ext.getCmp("map2")
            			map2.setMapCenter(results[0].geometry.location);
          			} else {
            			alert('Geocode was not successful for the following reason: ' + status);
          			}
        		});
      	}
		
      	
Ext.define('Triends.view.MapOverlay',{ // TingOpen에서 requires로 잡아주고 여기에서는 만들어 놓는다.
	extend: 'Ext.Panel',
	id: 'mapoverlay',
	config: {		
		layout: 'fit',
		floating: true,
		hideOnMaskTap: true,
		listeners: {
			hide: function() {
				this.destroy();
			}
		},
		modal: true,
		centered: true,
		width: 310,
		height: 400,
		items: [
				{
					xtype: 'toolbar',
					width: 300,
					docked: 'top',
					items: [{
		           		xtype: 'searchfield',
		           		id: 'map2search',
		           		width: 200,
		            	placeHolder: "Input city name",
		            	autocomplete: true,
		            	autoCreateField: true
					},
					{
		            	xtype: 'button',
		            	iconCls: 'search',
		            	iconMask: true,
		            	handler: function(){
		            		showAddress();
	            		}
	            	}]
				},
				{
		 	 		xtype: 'panel',
		 	 		docked: 'top',
		 	 		style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
		 	 		items:[
		 	 			{
		 	 				xtype: 'panel',
		 	 				style: 'margin-top:-2px',
		 	 				html: "<div valign='center' align='center'><font size='1'><b>더블클릭으로 위치를 선택하세요</b></font></div>"
		 	 			}]
 	 			},
				{
					xtype: 'panel',
					docked: 'bottom',
					layout: 'hbox',
					items: [
					{
						xtype: 'button',				
						flex: 1,
						text: '선택완료',
						handler: function(){
							if(selectedLocation == null){
									Ext.Msg.alert("","위치를 선택하세요");
									return;
							}else{
								var mapOverlay = Ext.getCmp("mapoverlay");
								localStorage.setItem("lat", lat);
								localStorage.setItem("lng", lng);
								Ext.Msg.alert("","위치가 선택되었습니다");
								mapOverlay.destroy();
							}
						}
					},
					{
						xtype: 'button',
						flex: 1,
						text: '닫기',
						handler: function(){
							var mapOverlay = Ext.getCmp("mapoverlay");
							mapOverlay.destroy();
						}
					}
					]
				}
				]
		}
});

// Tinginfo에서 보여지는 오버레이      	

Ext.define('Triends.view.MapOverlay2', { // TingOpen에서 requires로 잡아주고 여기에서는 만들어 놓는다.
	extend: 'Ext.Panel',
	id: 'mapoverlay2',
	config: {
		layout: 'fit',
		floating: true,
		hideOnMaskTap: true, //true?
		modal: true,
		centered: true,
		width: 310,
		height: 300,
		listeners: {
			hide: function(){
				this.destroy();
			}
		}	
	}
});

// TingModify에서 쓰는 MapOverlay!!


Ext.define('Triends.view.MapOverlay3',{ // TingModify에서 requires로 잡아주고 여기에서는 만들어 놓는다.
	extend: 'Ext.Panel',
	id: 'mapoverlay3',
	config:{
		layout: 'fit',
		floating: true,
		hideOnMaskTap: true,
		modal: true,
		centered: true,
		width: 310,
		height: 400,
		listeners: {
			hide: function() {
				this.destroy();
			}
		},
		items: [
				{
					xtype: 'toolbar',
					width: 300,
					docked: 'top',
					items: [{
		           		xtype: 'searchfield',
		           		id: 'map4search',
		           		width: 200,
		            	placeHolder: "Input city name",
		            	autocomplete: true,
		            	autoCreateField: true
					},
					{
		            	xtype: 'button',
		            	iconCls: 'search',
		            	iconMask: true,
		            	handler: function(){
		            		var geocoder;
							geocoder = new google.maps.Geocoder();
							
							function showAddress(){
								 var address = Ext.getCmp("map4search").getValue();
					       			 geocoder.geocode( { 'address': address}, function(results, status) {
					          			if (status == google.maps.GeocoderStatus.OK) {
					          				var map4 = Ext.getCmp("map4");
					            			map4.setMapCenter(results[0].geometry.location);
					    					var marker = new google.maps.Marker({
					    						map: map,
					    						position: results[0].geometry.location,
					    						icon: 'resource/images/mappin1.png'
					            			});
					          			} else {
					            			alert('Geocode was not successful for the following reason: ' + status);
					          			}
					        		});
					      	}
		            		showAddress();
	            		}
	            	}]
				},
				{
		 	 		xtype: 'panel',
		 	 		docked: 'top',
		 	 		style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
		 	 		items:[
		 	 			{
		 	 				xtype: 'panel',
		 	 				style: 'margin-top:-2px',
		 	 				html: "<div valign='center' align='center'><font size='1'><b>더블클릭으로 위치를 선택하세요</b></font></div>"
		 	 			}]
 	 			},
				{
					xtype: 'panel',
					docked: 'bottom',
					layout: 'hbox',
					items: [
					{
						xtype: 'button',				
						flex: 1,
						text: '선택완료',
						handler: function(){
							var tingnum = Ext.getCmp("tingmodify").getData().NUMBER;
							
							Ext.data.JsonP.request({
								url: 'http://itscreater.cafe24.com/Triends/TingMapModify.jsp',
								params: {num: tingnum, lat: lat, lng: lng},
								callbackkey: 'callback',
								success: function(){
									Ext.Msg.alert("","위치가 선택되었습니다");
								}
							})
							var mapOverlay3 = Ext.getCmp("mapoverlay3");
							var map4 = Ext.getCmp("map4");
							map4.destroy();
							mapOverlay3.destroy();
						}
					},
					{
						xtype: 'button',
						flex: 1,
						text: '닫기',
						handler: function(){
							var mapOverlay3 = Ext.getCmp("mapoverlay3");
							var map4 = Ext.getCmp("map4");
							map4.destroy();
							mapOverlay3.destroy();
						}
					}
					]
				}
				]
	}
});

Ext.define("Triends.Model.Message",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"Number", "Sender", "SenderID", "Getter", "GetterID","Message", "Confirm", "Date", "Time"
		]
	}
});

var MessageStore = Ext.create("Ext.data.Store",{
	model: "Triends.Model.Message",
	id: 'msgstore',
	listeners: {
		load: function() {
			var newmsg = 0;
        	MessageStore.each( function(model) {
    	    	if (model.data.Confirm == 0) {
	    	    	newmsg++;
            	}
           	});
           	if (newmsg != 0) {
           		var msgboxbtn = Ext.getCmp('msgboxbtn');
           		msgboxbtn.setBadgeText(newmsg);
	        }
		}
	},
	proxy: {
		type: "jsonp",
		callbackKey: 'callback',
		url: "http://itscreater.cafe24.com/Triends/Mymessage.jsp"
	},
	sorters: [
		{
			property: 'Date',
			direction: 'DESC'
		},
		{
			property: 'Time',
			direction: 'DESC'
		}
	]
	
});


Ext.define('Triends.view.Mymessage', {
	extend: 'Ext.dataview.DataView',
	xtype: 'mymsg',
	id: 'mymsg',
	config: {
		fullscreen: true,
    	store: MessageStore,
    	showAnimation: 'slideIn',
    	useComponents: true,
    	style: 'background: white',
		defaultType: 'MessageItem',
		items:[{
			xtype: 'panel',
			docked: 'top',
			height: 40,
			padding: 10,
			style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
			items: [{
				xtype: 'panel',
				width: 120,
				style: 'padding-left:10px',
				html: "<font size='4'><b>Messages<b/></font>"
			}]
		}],
    	listeners: {
    			
    		itemtap: function(list, index, target, model, e, eOpts) {
        		        
        		var msginfopanel = Ext.getCmp('msginfopanel');
        			msginfopanel.setData(model.data);
        		var msgnum = model.data.Number;
        		
        		Ext.data.JsonP.request({
 					url: 'http://itscreater.cafe24.com/Triends/MessageConfirm.jsp',
 					params: {num: msgnum},
 					callbackkey: 'callback',
 					success: function() {
 						var userid = Ext.getStore('UserStore').getAt(0).data.ID;
   			   			
   			   			var msgStore = Ext.getStore('msgstore');
            				msgStore.getProxy().setExtraParams({id: userid});
            				msgStore.load({
								callback: function() {  
									Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            							url: 'mainpage/account/msginfo'
        							}));
								}
            				});
 					}
 				});
        		
        	}
        }
	}
});

Ext.define('MessageItem', {
	extend: 'Ext.dataview.component.DataItem',
    xtype: 'MessageItem',
    config: {
		listeners: {
			updatedata: function(dataitem, newData, eOpts) {
				var confirm = this.getRecord().get('Confirm');
				var sender = this.getRecord().get('Sender');
				var msg = this.getRecord().get('Message');
				var panel = this.getItems().items[0];
				
				if (confirm == 0) {
					if(msg.match("<br>") != null)
					{
						msg = msg.replace(/<br>/gi, " ");
					}
					panel.setHtml(
						"<table style='table-layout:fixed;'>"+
							"<tr>"+
								"<td valign='center' align='center' width=120><font size='2'><b>"+sender+"</b></font></td>"+
								"<td valign='center'>" +
									'<div class="ellipsis"><nobr><font size="2"><b>'+msg+'</b></font></nobr></div>' +
								"</td>"+
							"</tr>"+
						"</table>"
					);
				} else if (confirm == 1) {
					if(msg.match("<br>") != null)
					{
						msg = msg.replace(/<br>/gi, " ");
					}
					panel.setHtml(
						"<table style='table-layout:fixed;'>"+
							"<tr>"+
								"<td valign='center' align='center' width=120><font size='2'>"+sender+"</font></td>"+
								"<td valign='center'>" +
									"<div class='ellipsis'><nobr><font size='2'>"+msg+"</font><nobr></div></td>"+
							"</tr>"+
						"</table>"
					);
				}
			}
		},
		items: [{
			xtype: 'panel',
			height: 50,
			style: 'border-bottom:1px silver solid; background:white; padding-top:10px'
		}]
    }
});

Ext.define('Triends.view.Mymessageinfo', {
	requires: ['Triends.view.Othersinfo', 'Triends.view.Sendmessage'],
	extend: 'Ext.Panel',
	xtype: 'msginfo',
	id: 'msginfo',
	config: {
		layout: 'vbox',
		fullscreen: true,
		scrollable: true,
		items: [
		{
			xtype: 'panel',
			id: 'msginfopanel',
			minHeight: 600,
			style: {'padding':'15px', 'background':'white'},
			tpl: [
			"<div>",
			"<b><font size='3'>Sender:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Sender}</font></b><br>" +
			"<hr color'#CBCAC7' width='100%'>" +
			"<b><font size='3'>Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{Date}&nbsp;&nbsp;{Time}</font></b><br>" +
			"<hr color'#CBCAC7' width='100%'><br><br>",
			"{Message}",
			"</div>"
			]
		},
		{
			xtype: 'panel',
			docked: 'top',
			layout: 'hbox',
			height: 40,
			padding: 5,
			style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))', 'padding-left':'15px'},
			items: [
				{
					xtype: 'button',
					ui: 'small',
					width: 50,
					text: '답장',
					handler: function() {
		        		var thisview = Ext.getCmp('msginfopanel');
				    	var sender = thisview.getData().Sender;
				    	var getter = thisview.getData().Getter;
				    	var senderID = thisview.getData().SenderID;
				    	var getterID = thisview.getData().GetterID;
				    	
				    	var send = Ext.create('Triends.view.Sendmessage');
				    	var getterpanel = Ext.getCmp('getterpanel');
				    	getterpanel.setData({SenderID: getterID, Sender: getter,  GetterID: senderID, Getter: sender});
				    	send.setData({SenderID: getterID, Sender: getter,  GetterID: senderID, Getter: sender});
				    	Ext.Viewport.add(send);
		    	    }
				},
		 		{
		 			
					xtype: 'button',
					ui: 'small',
					width: 50,
					style: 'margin-left:10px',
					text: '삭제',
					handler: function() {
						Ext.Msg.show({
  							title: '',
  							message: '쪽지를 삭제하시겠습니까?',
   		        			width: 300,
   							buttons:  [{
   								id: 'ok',
   								text: 'Ok',
   								ui: 'action'
   							},
   							{	
   								id: 'cancel',
   								text: 'Cancel'
   							}],   					
   							fn: function(buttonId) {
    	   						if (buttonId == 'Ok') {
									var thisview = Ext.getCmp('msginfopanel');
				    				var num = thisview.getData().Number;
				    	
		    	  					Ext.data.JsonP.request({
		   								url: 'http://itscreater.cafe24.com/Triends/MessageDelete.jsp',
		   								params: {
		   									num : num
		   								},
		          						callbackKey: 'callback',
		          						success: function(result) {
			          				
		          							var userid = Ext.getStore('UserStore').getAt(0).data.ID;
						   			   		
		   			   						var msgStore = Ext.getStore('msgstore');
		            						msgStore.getProxy().setExtraParams({id: userid});
		            						msgStore.load({
		            							callback: function() {
		            								navigator.app.backHistory();
		            							}
		            						});
		         						}
		    		  				});	
    	   						} else if (buttonId == 'Cancel') {
       								Ext.emptyFn
       							}
   							}
						});
						
						
						
		    		}
				}]
		}]
	}
});

Ext.define('Triends.view.Noticeinfo', {
	extend: 'Ext.Panel',
	xtype: 'noticeinfo',
	id: 'noticeinfo',
	config: {
		fullscreen: true,
		scrollable: true,
		layout: 'vbox',
		items: [{
			xtype: 'panel',
			layout: 'hbox',
			style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))', 'padding':'15px'},
			items: [{
				xtype: 'panel',
				minWidth: '80%',
				maxWidth: '80%',
				id: 'noticetitlepanel',
				tpl: [
				"<p style='white-space:pre-line;'>"+
				"<b><font size='4'>{Title}</font></b><br>" +
				"</p>"
				]
			}]
		},
		{
			xtype: 'panel',
			layout: 'vbox',
			style: 'padding:30px;background:white',
			items:[{
				xtype: 'panel',
				style: 'margin-left:-125px;left:50%;',
				docked: 'top',
				width: 250,
				height: 250,
				html: '<img src="resource/images/triendsaccount1.png" width="250px" height="250px">'
			},
			{
				xtype: 'panel',
				id: 'noticecontentpanel',
				style: 'margin-top:30px',
				docked: 'top',
				tpl: ["<p style='white-space:pre-line;'><font size='3'>{Content}</font></p>"]
			}]
		}]
	}
});

Ext.define("Triends.Model.Noticelist",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"Number", "Title", "Content", "Date", "Time"
		]
	}
});

var noticestore = Ext.create("Ext.data.Store",{
	model: "Triends.Model.Noticelist",
	id: 'noticestore',
	proxy: {
		type: "jsonp",
		url: 'http://itscreater.cafe24.com/Triends/Notice.jsp', 
		callbackkey: 'callback'
	},
	sorters: [
		{
			property: 'DATE',
			direction: 'DESC'
		},
		{
			property: 'TIME',
			direction: 'DESC'
		}
	]
});

Ext.define('Triends.view.Noticelist', {
	extend: 'Ext.Panel',
	xtype: 'noticelist',
	id: 'noticelist',
	config: {
		items: [{
	   		xtype: 'panel',
	   		docked: 'top',
	   		height: 30,
	   		style: {'margin-bottom':'20px','padding-top':'3px','padding-left':'27px','background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))'},
	   		html: '<b>Notice</b>'
	   	},
	   	{
	   		xtype: 'list',
	   		scrollable: false,
	   		margin: 10,
	   		pressedCls: "x-item-selected",
			selectedCls: "",
			pressedDelay: 50,
 			style: 'background:white;',
	 		store: noticestore,
		   	itemTpl: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='2'><b>{Title}</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>",
		   	listeners: {
		   		itemtap: function(list, index, target, model, e, eOpts) {
			    	var noticetitlepanel = Ext.getCmp('noticetitlepanel');
			    	var noticecontentpanel = Ext.getCmp('noticecontentpanel');
			    	noticetitlepanel.setData(model.data);
			    	noticecontentpanel.setData(model.data);
			    	
			    	Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            		url: 'mainpage/settings/noticeinfo'
		        	}));
	   			}
	   		}
	   	}]
	}
});

function fireClick(node){
	if ( document.createEvent ) {
		var evt = document.createEvent('MouseEvents');
		evt.initEvent('click', false, true);
		node.dispatchEvent(evt);	
	} else if( document.createEventObject ) {
		node.fireEvent('onclick') ;	
	} else if (typeof node.onclick == 'function' ) {
		node.onclick();	
	}
}

function openOtherinfo(otherid, cacaocheck) {
	if (cacaocheck == null) {
		cacaocheck = 'cannot';
	}
	var activetab = Ext.getCmp('main').getActiveItem().id;
	var OthersStore = Ext.getStore('OthersStore'+otherid);
	if (Ext.typeOf(OthersStore) == 'object') {
		OthersStore.removeAll();
	} else {
		OthersStore = Ext.create("Ext.data.Store",{
			model: "Triends.Model.Othersinfo"
		});
		OthersStore.setStoreId('OthersStore'+otherid);
	}
	
	var otherHOSTtingStore = Ext.getStore('otherHOSTtingStore'+otherid);
	if (Ext.typeOf(otherHOSTtingStore) == 'object') {
		otherHOSTtingStore.removeAll();
	} else {
		otherHOSTtingStore = Ext.create("Ext.data.Store",{
			model: "Triends.OtherTinglist",
			sorters: [{
				property: 'STARTDATE',
				direction: 'ASC'
			},
			{
				property: 'STARTTIME',
				direction: 'ASC'
			}]
		});
		otherHOSTtingStore.setStoreId('otherHOSTtingStore'+otherid);
	}
		    	
	
	var otherATTENDtingStore = Ext.getStore('otherATTENDtingStore'+otherid);
	if (Ext.typeOf(otherATTENDtingStore) == 'object') {
		otherATTENDtingStore.removeAll();
	} else {
		otherATTENDtingStore = Ext.create("Ext.data.Store",{
			model: "Triends.OtherTinglist",
			sorters: [{
				property: 'STARTDATE',
				direction: 'ASC'
			},
			{
				property: 'STARTTIME',
				direction: 'ASC'
			}]
		});
		otherATTENDtingStore.setStoreId('otherATTENDtingStore'+otherid);
	}
	
		    
	Ext.data.JsonP.request({
    	url: 'http://itscreater.cafe24.com/Triends/Othersinfo.jsp',
        params: {id: otherid},
        callbackKey: 'callback',
            success: function(result) {
            	OthersStore.setData(result);
            	
           	    Ext.data.JsonP.request({
        			url: 'http://itscreater.cafe24.com/Triends/UserHostTing.jsp',
        			params: {id: otherid},
        			callbackKey: 'callback',
        			success: function(result) {
            			otherHOSTtingStore.setData(result);
            			
            			Ext.data.JsonP.request({
        					url: 'http://itscreater.cafe24.com/Triends/UserAttendTing.jsp',
        					params: {id: otherid},
        					callbackKey: 'callback',
        					success: function(result) {
            					otherATTENDtingStore.setData(result);
            					Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
        							url: 'otherinfo/'+ activetab + '/' + otherid + '/' + cacaocheck
    							}));
        					}
    					});
        			}
    			});
            }
    	});
		    	

            		
   		
            		
    
}

Ext.define("Triends.Model.Othersinfo",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"ID", "Name", "Email", "Age", "Gender", "Introduction", "Cacao"
		]
	}
});

Ext.define('Triends.view.Othersinfo', {
 	extend: 'Ext.Panel',
	requires: ['Triends.view.Sendmessage'],
 	id: 'othersinfo',
 	xtype: 'othersinfo',
	config: {
 		style: 'position:relative',
 		layout: 'vbox',
 		fullscreen: true,
 		scrollable: true,
 		showAnimation: 'slideIn',
 		listeners: {
 			deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					Ext.getCmp('othersinfo').destroy();
				}
 		},
 	items: [{
 			xtype: 'panel',
 			layout: 'hbox',
	 		minHeight: 200,
 			style: {'padding':'15px', 'border-bottom':'1px #CBCAC7 solid'},
 			items: [
 			{
 				xtype: 'panel',
 				flex: 1,
 				items:[{
 					xtype: 'panel',
 					style: {'left':'50%', 'margin-left':'-50px', 'padding-top':'30px'},
					id: 'otherimg',
					width: 100,
					height: 100,
					listeners: {
						tap: {
							element: 'element',
							fn: function() {
							}
						}
					}
 				}]
 			},
 			{
 				xtype: 'panel',
 				flex: 1,
 				layout: 'vbox',
 				items:[{
 					xtype: 'dataview',
 					id: 'otherinfoview',
 					flex: 1,
 					margin: '5px',
 					scrollable: false,
 					itemTpl: "<div align='center'><b><font size='4'>{Name}</font></b></div>"
 				},
 				{
 					xtype: 'panel',
 					flex:1,
 					layout: 'hbox',
 					style: 'margin-top:10px; margin-bottom:-10px',
 					items: [
 						{
	 						xtype: 'panel',
	 						id: 'cacaopanel',
		 					style: 'left:50%; margin-left:-75px;padding-left:5px',
	 						width: '150px',
	 						layout: 'hbox',
	 						hidden: true,
	 						items: [
			 					{
			 						xtype: 'image',
			 						style: 'margin-left:3px',
			 						src: 'resource/images/cacao.png',
			 						width: 24,
			 						height: 24
			 					},
			 					{
				 					xtype: 'dataview',
				 					style: 'margin-left: 15px',
				 					id: 'otherinfocacao',
				 					scrollable: false,
				 					itemTpl: "<div align='center'><font size='3'>{Cacao}</font></div>"
			 					}
 							]
 					}]
 				},
 				{
 					xtype: 'panel',
 					flex:1,
 					items: [{
 						xtype: 'button',
 						style: 'border: 2px outset',
		 				id: 'msgboxbtn2',
		 				ui: 'small',
		 				text: 'Send Message',
		 				width: 150,
		    		   	iconCls: 'mail',
		    	 	   	iconMask: true,
	 					centered: true,
		   			   	handler: function() {
		   			   		var userid = Ext.getStore('UserStore').getAt(0).data.ID;
		   			   		var username = Ext.getStore('UserStore').getAt(0).data.Name;
		   			   		var otherid = Ext.getCmp('otherinfoview').getStore().getAt(0).getData().ID;
		   			   		var othername = Ext.getCmp('otherinfoview').getStore().getAt(0).getData().Name;
				    		var send = Ext.create('Triends.view.Sendmessage');
				    		var getterpanel = Ext.getCmp('getterpanel');
				    		getterpanel.setData({SenderID: userid, Sender: username, GetterID: otherid, Getter: othername});
				    		send.setData({SenderID: userid, Sender: username, GetterID: otherid, Getter: othername});
				    		Ext.Viewport.add(send);
            			}	
 					}]
 				},
 				{
	 				xtype: 'panel',
	 				flex: 1,
	 				items: [{
	 					xtype: 'button',
		 				id: 'FBbutton',
	 					width: 150,
 						iconCls: 'facebook',
 						iconMask: true,
 						style: 'border: 2px outset;',
 						ui: 'small',
// 						text: 'Go to Facebook',
 						centered: true,
 						handler: function(){
 							var el = document.getElementById('moveFB');
 							fireClick(el);
 						}
	 				}]
 				}
 				]
 			}]
 		},
 		{
 			xtype: 'panel',
 			layout: 'vbox',
 			style: {'padding':'15px', 'border-bottom':'1px #CBCAC7 solid'},
 			minHeight: 150,
 			items: [
 				{
					xtype: 'panel',
					style: 'margin-bottom:10px',
					html: "<p style='margin-left:5px'><font size='4'><b>Introduction</b></font></p>"
				},
				{
					xtype: 'dataview',
					id: 'otherintroview',
					scrollable: false,
					itemTpl:"&nbsp;<font size='3'>{Introduction}</font>"
				}
 			]
 		},
		{
				xtype: 'othertinglist'
		}]
	}
});

Ext.define("Triends.OtherTinglist",{
	extend: "Ext.data.Model",
	config: {
		fields: ["NUMBER", "ID", "HOST", "TITLE", "THEME", "LAT", "LNG", "CONTENT", "STARTDATE", "STARTTIME", "Date", "Time"]
	}
});

Ext.define('Triends.view.OtherTinglist', {
	extend: 'Ext.Panel',
	id: 'othertinglist',
	xtype: 'othertinglist',
	config: {
		layout: 'vbox',
		items: [
			{
				xtype: 'panel',
		    	style: {'margin':'10px'} ,
		    	html: "<p style='margin-left:10px'><font size='4'><b>Hosting</b></font></p>"
			},
			{
				xtype: 'panel',
				style: {'margin':'10px'},
				minHeight: 70,
				items: [{
						xtype: 'list',
						id: 'otherhosttingview',
						style: 'background:white',
						pressedCls: "x-item-selected",
						selectedCls: "",
						pressedDelay: 50,
						scrollable: false,
						itemTpl:"<table>"+
										"<tr>" +
											"<td rowspan='2' align='center' valign='center' width=50 style='word-break:break-all'><img src='resource/images/{THEME}.png' width='48px' height='48px'></td>" +
											"<td valign='center'><p style='margin-left:20px'><font size='4'>{TITLE}</font></p></td>" +
										 "</tr>" +
										"<tr>" +
											"<td valign='center'><p style='margin-left:20px'><font size='2'>{STARTDATE}&nbsp;&nbsp;&nbsp;{STARTTIME}</font></p></td>" +
										"</tr>"+
									"</table>",
			//			useComponents: true,
			//			defaultType: 'UserTingItem',
						listeners: {
							itemtap: function(dataview, index, target, model, e, eOpts) {
								var tingnum = model.data.NUMBER;
								openTinginfo(model, tingnum)
							}
						}		
					}]
			},
			{
				xtype: 'panel',
		    	style: {'margin':'10px'} ,
		    	html: "<p style='margin-left:10px'><font size='4'><b>Attending</b></font></p>"
			},
			{
				xtype: 'panel',
				style: {'margin':'10px'},
				items: [{
					xtype: 'list',
					id: 'otherattendtingview',
					style: 'background:white',
					pressedCls: "x-item-selected",
					selectedCls: "",
					pressedDelay: 50,
					minHeight: 70,
					scrollable: false,
					itemTpl:"<table>"+
								"<tr>" +
									"<td rowspan='2' align='center' valign='center' width=50 style='word-break:break-all'><img src='resource/images/{THEME}.png' width='48px' height='48px'></td>" +
									"<td valign='center'><p style='margin-left:20px'><font size='4'>{TITLE}</font></p></td>" +
								 "</tr>" +
								"<tr>" +
									"<td valign='center'><p style='margin-left:20px'><font size='2'>{STARTDATE}&nbsp;&nbsp;&nbsp;{STARTTIME}</font></p></td>" +
								"</tr>"+
							"</table>",
		//			useComponents: true,
		//			defaultType: 'UserTingItem',
					listeners:{
						itemtap: function(dataview, index, target, model, e, eOpts) {
							var tingnum = model.data.NUMBER;
							openTinginfo(model, tingnum)					
						}
					}	
				}]
		}]
	}
});
	
//Ext.define('OtherTingItem', {
//	extend: 'Ext.dataview.component.DataItem',
//    xtype: 'UserTingItem',
//	config: {
//		items: [{
//			xtype: 'panel',
//			tpl: '{TITLE}<br>{STARTDATE} {STARTTIME}'
//		}]
//    }
//});

function writerinfo() {
				var thisview = Ext.getCmp('postinfopanel1');
		    	var otherid = thisview.getData().ID;
		    	openOtherinfo(otherid)
}

Ext.define('Triends.view.Postinfo', {
	extend: 'Ext.Panel',
	xtype: 'postinfo',
	id: 'postinfo',
	config: {
		fullscreen: true,
		scrollable: true,
		showAnimation: 'slideIn',
		layout: 'vbox',
		items: [{
			xtype: 'panel',
			layout: 'hbox',
			style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))', 'padding':'15px'},
			items: [{
				xtype: 'panel',
				minWidth: '80%',
				maxWidth: '80%',
				layout: 'vbox',
				items:[{
					xtype: 'panel',
					id: 'postinfopanel1',
					tpl: [
					"<div>",
					"<b><font size='5'>{TITLE}</font></b>"
					]
				},
				{
					xtype: 'panel',
					id: 'postinfopanel2',
					tpl:[
					"<font size='2'>{WRITER}</font></h><br><h><font size='2'>{DATE}&nbsp;&nbsp;&nbsp;{TIME}</font></h>" +
					"</div>"
					],
					listeners: {
						tap: {
							element: 'element',
							fn: function() {
								writerinfo();
							}
						}
					}
				}]
			},
			{
				xtype: 'panel',
				layout: 'vbox',
				width: 60,
				items:[{
					xtype: 'panel',
					style: 'margin-bottom:3px',
					flex: 3,
					items: [{
						xtype: 'button',
						iconCls: 'trash',
						ui: 'small',
						iconMask: true,
						width: '48px',
						height: '32px',
						centered: true,
						hidden: true,
						id: 'postnormaldeletebtn',
						handler: function() {
				          	Ext.Msg.show({
			  					title: '알림',
			  					message: '삭제하시겠습니까?',
			   		            width: 300,
			   					buttons:  [{
			   						id: 'ok',
			   						text: 'Ok',
			   						ui: 'action'
			   					},
			   					{	id: 'cancel',
			   						text: 'Cancel'
			   					}],   					
			   					fn: function(buttonId) {
			       					if (buttonId == 'Ok') {
			       						var thisview = Ext.getCmp('postinfopanel1');
					    				var num = thisview.getData().Number;
					    	
			    	  					Ext.data.JsonP.request({
			   								url: 'http://itscreater.cafe24.com/Triends/PostDelete.jsp',
			   								params: {
			   									num : num
			   								},
			          						callbackKey: 'callback',
			          						success: function(result) {
			          							
			          							var postStore = Ext.getStore('poststore');
			         							postStore.load({
			         								callback: function() {
			         									navigator.app.backHistory();
			         								}
			         							});
			         				
			         							
			         						}
			    		  				});	
			       					} else if (buttonId == 'Cancel') {
			       						Ext.emptyFn
			       					}
			   					}
							});
						}
					}]
					
				},
				{
					xtype: 'spacer',
					flex: '1'
				},
				{
					xtype: 'panel',
					flex: 3,
					items:[{
						xtype: 'button',
						iconCls: 'settings',
						iconMask: true,
						width: '48px',
						height: '32px',
						ui: 'small',
						centered: true,
						hidden: true,
						id: 'postnormalmodifybtn',
						handler: function(){
							var titlemodify = Ext.getCmp("titlemodify");
							var contentmodify = Ext.getCmp("contentmodify")
							var postinfodata = Ext.getCmp("postinfopanel").getData();
							var titledata = postinfodata.TITLE;
							var contentdata = postinfodata.CONTENT;
							titlemodify.setValue(titledata);
							Ext.getCmp('postmdftitlecount').setHtml(titledata.length+'/50');
							if (contentdata.match("<br>") != null || contentdata.match("&nbsp;") != null){
								contentdata = contentdata.replace(/&nbsp;/gi, " "); /*/gi를 써서 전체 문자열을 바꿔준다 */
								contentdata = contentdata.replace(/<br>/gi, "\n");
							}
							contentmodify.setValue(contentdata);
							Ext.getCmp('postmdftextcount').setHtml(contentdata.length+'/250');
							Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage/post/postnormalmodify'
	        				}));
						}
					}]
						
				}]
			}]
		},
		
		{
			xtype: 'panel',
			id: 'postcontentpanel',
			style: {'border-bottom':'1px #CBCAC7 solid','padding':'15px'},
			minHeight: '300px',
			tpl: ["<p><font size='3'>{CONTENT}</font></p>"]
		},
		{
 	 		xtype: 'panel',
 	 		style: 'padding-top:15px; padding-left:15px;',
 	 		items:[
 	 			{
 	 				xtype: 'panel',
 	 				style: 'margin-bottom:-10px',
 	 				html: "<p style='margin-left:5px;'><font size='4'><b>Comment</b></font></p>"
 	 			},
 	 			{
 	 				xtype: 'postnormalcomment'
 	 			}
 	 		]
 	 	}]
	}
});

function writerinfoloc(){
	    	//사용자정보 획득을 위해 ID값 추출
	    	var thisview = Ext.getCmp('postlocationtitlepanel1');
	    	var otherid = thisview.getData().ID;
	    	openOtherinfo(otherid)
}

Ext.define('Triends.view.PostinfoLocation', {
	requires:'Triends.view.PostLocationComment',
	extend: 'Ext.Panel',
	xtype: 'postinfolocation',
	id: 'postinfolocation',
	config: {
		fullscreen: true,
		scrollable: true,
		showAnimation: 'slideIn',
		layout: 'vbox',
		items: [{
			xtype: 'panel',
			layout: 'hbox',
			style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))', 'padding':'15px'},
			items: [{
				xtype: 'panel',
				minWidth: '80%',
				maxWidth: '80%',
				items: [{
					xtype: 'panel',
					id: 'postlocationtitlepanel1',
					tpl: [
					"<div>",
						"<b><font size='5'>{TITLE}</font></b><br>"
					]
				},
				{
					xtype: 'panel',
					id: 'postlocationtitlepanel2',
					tpl:[
					"<font size='2'>{WRITER}</font></h><br><h><font size='2'>{DATE}&nbsp;&nbsp;&nbsp;{TIME}</font>" +
					"</div>"]
				}]
			},
			{
				xtype: 'panel',
				layout: 'vbox',
				width: 60,
				items:[{
					xtype: 'panel',
					style: 'margin-bottom:3px',
					flex: 3,
					items:[{
						xtype: 'button',
						iconCls: 'trash',
						iconMask: true,
						ui: 'small',
						width: '48px',
						height: '32px',
						hidden: true,
						centered: true,
						id: 'postlocationdeletebtn',
						handler: function() {
				          	Ext.Msg.show({
			  					title: '알림',
			  					message: '삭제하시겠습니까?',
			   		            width: 300,
			   					buttons:  [{
			   						id: 'ok',
			   						text: 'Ok',
			   						ui: 'action'
			   					},
			   					{	id: 'cancel',
			   						text: 'Cancel'
			   					}],   					
			   					fn: function(buttonId) {
			       					if (buttonId == 'Ok') {
			       						var thisview = Ext.getCmp('postlocationtitlepanel1');
					    				var num = thisview.getData().Number;
					    	
						    	  		Ext.data.JsonP.request({
			   								url: 'http://itscreater.cafe24.com/Triends/PostDelete.jsp',
			   								params: {
			   									num : num
			   								},
			          						callbackKey: 'callback',
			          						success: function(result) {
			         							var postLocationStore = Ext.getStore("postlocationstore");
			    								postLocationStore.load({
			    									callback: function() {
			    										navigator.app.backHistory()
			    									}
			    								});
						         					
			         						}
			    		  				});	
						       		} else if (buttonId == 'Cancel') {
			       						Ext.emptyFn
			       					}
			   					}
							});
					}
					}]	
				},
				{
					xtype: 'spacer',
					flex: 1
				},
				{
					xtype: 'panel',
					flex: 3,
					items:[{
						xtype: 'button',
						iconCls: 'settings',
						iconMask: true,
						width: '48px',
						height: '32px',
						ui: 'small',
						hidden: true,
						centered: true,
						id: 'postlocationmodifybtn',
						handler: function(){
							var titlemodify = Ext.getCmp("titlelocationmodify");
							var contentmodify = Ext.getCmp("contentlocationmodify");
							var continentmodify = Ext.getCmp("continent3");
							var nationmodify = Ext.getCmp("nation3");
							
							var postinfodata = Ext.getCmp("postlocationtitlepanel").getData();
							var titledata = postinfodata.TITLE;
							var contentdata = postinfodata.CONTENT;
							var continentdata = postinfodata.CONTINENT;
							var nationdata = postinfodata.NATION;
							
							continentmodify.setValue(continentdata);
							nationmodify.setValue(nationdata);
							titlemodify.setValue(titledata);
							Ext.getCmp('locmdftitlecount').setHtml(titledata.length+'/50');
							if (contentdata.match("<br>") != null || contentdata.match("&nbsp;") != null){
								contentdata = contentdata.replace(/&nbsp;/gi, " "); /*/gi를 써서 전체 문자열을 바꿔준다 */
								contentdata = contentdata.replace(/<br>/gi, "\n");
							}
							contentmodify.setValue(contentdata);
							Ext.getCmp('locmdftextcount').setHtml(contentdata.length+'/250');
							Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage/post/postlocationmodify'
	        				}));
						}		
					}]
				}]
			}]
		},
		{
			xtype: 'panel',
			id: 'postlocationcontentpanel',
			minHeight: '300px',
			style: {'border-bottom':'1px #CBCAC7 solid','padding':'15px'},
			tpl: ["<p><font size='3'>{CONTENT}</font></p>"]
		},
		{
 	 		xtype: 'panel',
 	 		style: 'padding-top:15px; padding-left:15px;',
 	 		items:[
 	 			{
 	 				xtype: 'panel',
 	 				style: 'margin-bottom:-10px',
 	 				html: "<p style='margin-left:5px;'><font size='4'><b>Comment</b></font></p>"
 	 			},
 	 			{
 	 				xtype: 'postlocationcomment'
 	 			}
 	 		]
 	 	}]
	}
});

Ext.define('Triends.view.PostingLocation', {
 	extend: 'Ext.form.Panel',
 	xtype: 'postinglocation',
 	id: 'postinglocation',
 	config: {
 		fullscreen: true,
 		showAnimation: 'slideIn',
 		listeners: {
 			deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
	 					Ext.getCmp('continent').reset();
	 					Ext.getCmp('nation').reset();
	 					Ext.getCmp('locationtitlefield').reset();
	 					Ext.getCmp('locationcontentfield').reset();
				}
 		},
 		items: [
 		{
 			xtype: 'locationfield1'
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Title',
 			items: [{
 				xtype: 'textfield',
 				name: 'title',
 				style: 'border:3px inset',
 				id: 'locationtitlefield'
 			}]
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Content',
 			items: [{
 				xtype: 'textareafield',
 				name: 'content',
 				height: 200,
 				maxRows: 7,
 				style: 'border:3px inset',
 				id: 'locationcontentfield'
 			}]
 		},
 		{
 			xtype: 'panel',
 			layout: 'hbox',
 			items:[{
 				xtype: 'button',
	 			text: '등록',
	 			style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 		width: '100%',
	 			handler: function(){
	 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
	 				var username = Ext.getStore('UserStore').getAt(0).data.Name;
	 				
	 				var titlefield = Ext.getCmp('locationtitlefield');
	 				var contentfield = Ext.getCmp('locationcontentfield');
	 				var continent = Ext.getCmp('continent');
	 				var nation = Ext.getCmp('nation');
	 				
	 				if(continent.getValue() == ""){
	 					Ext.Msg.alert("","대륙을 선택하세요");
	 					return;
	 				}
	 				if(nation.getValue() == ""){
	 					Ext.Msg.alert("","국가를 선택하세요");
	 					return;
	 				}
	 				if(titlefield.getValue() == ""){
	 					Ext.Msg.alert("","Title을 입력하세요");
	 					return;
	 				}
	 				if(contentfield.getValue() == ""){
	 					Ext.Msg.alert("","Content를 입력하세요");
	 					return;
	 				}
	 				
	 				Ext.Ajax.request({
	 					url: 'http://itscreater.cafe24.com/Triends/Posting.jsp',
	 					params: {
	 						id: userid,
	 						name: username,
	 						title: titlefield.getValue(), 
	 						content: contentfield.getValue(),
	 						continent: continent.getValue(), 
	 						nation: nation.getValue()
	 					},
	 					success: function(response){
	 							var postLocationStore = Ext.getStore("postlocationstore");
	 									postLocationStore.removeAll();
				 						postLocationStore.setProxy({
											type: "jsonp",
											url: 'http://itscreater.cafe24.com/Triends/PostLocationList.jsp',
											extraParams: {continent: continent.getValue(),
														  nation: nation.getValue()},
											callbackkey: 'callback',
											pageParam: 'pages',
											limitParam: 'rpp',
											reader: {
												type: "json",
												rootProperty: "results",
												totalProperty: "total"
											}
										})
										postLocationStore.loadPage(1);
	 						Ext.Msg.show({
	 							message: '글이 등록되었습니다',
	 							buttons:[{text: '확인', itemId: 'ok',ui: 'action'}],
	 							fn: function(buttonId){
	 								if(buttonId == 'ok'){
	 								
										Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            								url: 'mainpage'
        								}));
	 								}
	 							}
	 						});
							localStorage.removeItem(continent);
							localStorage.removeItem(nation);
							localStorage.setItem("continent", continent.getValue());
							localStorage.setItem("nation", nation.getValue());
	 						continent.reset();
	 						nation.reset();
	 						titlefield.reset();
	 						contentfield.reset();
	 						
	 						
	        			}
	 				});
 				}
 			}]
 		},
 		{
 				
 		}]
 	}
});

Ext.define('Triends.view.PostingNormal', {
 	extend: 'Ext.form.Panel',
 	xtype: 'postingnormal',
 	id: 'postingnormal',
 	config: {
 		fullscreen: true,
 		showAnimation: 'slideIn',
 		listeners: {
 			deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
	 					Ext.getCmp('titlefield').reset();
	 					Ext.getCmp('contentfield').reset();
				}
 		},
 		items: [{
 			xtype: 'fieldset',
 			title: 'Title',
 			items: [{
 				xtype: 'textfield',
 				name: 'title',
 				style: 'border:3px inset',
 				id: 'titlefield'
 			}]
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Content',
 			items: [{
 				xtype: 'textareafield',
 				id: 'contentfield',
 				name: 'content',
 				height: 300,
 				maxRows: 12, // 이걸 잡아줘야 커서 이동 가능
 				style: 'border:3px inset'
 			}]
 		},
 		{
 			xtype: 'panel',
 			layout: 'hbox',
 			items:[{
 				xtype: 'button',
	 			text: '등록',
	 			style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 		width: '100%',
	 			handler: function(){
	 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
	 				var username = Ext.getStore('UserStore').getAt(0).data.Name;
	 				
	 				var titlefield = Ext.getCmp('titlefield');
	 				var contentfield = Ext.getCmp('contentfield');
	 				
	 				if(titlefield.getValue() == ""){
	 					Ext.Msg.alert("","Title을 입력하세요");
	 					return;
	 				}
	 				if(contentfield.getValue() == ""){
	 					Ext.Msg.alert("","Content를 입력하세요");
	 					return;
	 				}
	 				
	 				Ext.Ajax.request({
	 					url: 'http://itscreater.cafe24.com/Triends/Posting.jsp',
	 					params: {
	 						id: userid,
	 						name: username,
	 						title: titlefield.getValue(), 
	 						content: contentfield.getValue()
	 					},
	 					success: function(response) {
//	 					
							Ext.Msg.show({
	 							message: '글이 등록되었습니다',
	 							buttons:[{text: '확인', itemId: 'ok',ui: 'action'}],
	 							fn: function(buttonId){
	 								if(buttonId == 'ok'){
				 						var postStore = Ext.getStore('poststore');
				 						postStore.loadPage(1); // 이걸 넣었더니 paging후 글을 써도 잘 나온다
	 								}
	 							}
	 						});
	 						
	 						titlefield.reset();
	 						contentfield.reset();
	 						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage'
        					}));
	 					}
	 				});
 				}
 			}]
 				
 		}]
 	}
});

Ext.define("Triends.Model.PostLocationComment",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"Number", "PostNumber", "WriterID", "Writer", "Text", "Date", "Time"
		]
	}
});

var PostLocationCommentStore = Ext.create("Ext.data.Store",{
	model: "Triends.Model.PostLocationComment",
	id: 'PostLocationCommentStore',
	proxy: {
		type: "jsonp",
		callbackKey: 'callback',
		url: "http://itscreater.cafe24.com/Triends/PostCommentList.jsp"
	},
	sorters: [
		{
			property: 'Date',
			direction: 'ASC'
		},
		{
			property: 'Time',
			direction: 'ASC'
		}
	]
});

Ext.define('Triends.view.PostLocationComment', {
	extend: 'Ext.dataview.DataView',
	xtype: 'postlocationcomment',
	config: {
 		minHeight: 100,
 		style: 'margin-top:10px;',
 		width:'100%',
 		scrollable: false,
 		styleHtmlContent: true, // 이게 있으면 CSS가 제대로 안먹을수도, 없으면 하이퍼링크 안걸림
 		store: PostLocationCommentStore,
	   	useComponents: true,
		defaultType: 'PostLocationCommentItem',
	   	items: [{
    		xtype: 'panel',
    		docked: 'bottom',
    		layout: 'hbox',
    		style: "padding-right:15px",
    		items: [{
    			xtype: 'textfield',
    			id: 'postlocationcommentText',
   				flex: 9,
   				style: 'height: 30px; font-size: 70%; padding: 0px; margin-top:3px;'
    		},
    		{
    			xtype: 'button',
    			iconCls: 'compose',
    			width: 50,
    			iconMask: true,
    			flex: 1,
    			handler: function() {
    				var thisview = Ext.getCmp('postlocationtitlepanel1');
	        		var postnum = thisview.getData().Number;
		    		var userid = Ext.getStore('UserStore').getAt(0).data.ID;
		    		var username = Ext.getStore('UserStore').getAt(0).data.Name;
		    		var text = Ext.getCmp('postlocationcommentText').getValue();
		    		
		    		Ext.Ajax.request({
 						url: 'http://itscreater.cafe24.com/Triends/PostCommentWrite.jsp',
 						params: {
 							id: userid,
 							name: username,
 							num: postnum, 
 							text: text
 						},
 						success: function(response) {
 							var PostLocationCommentStore = Ext.getStore('PostLocationCommentStore');
 							PostLocationCommentStore.getProxy().setExtraParams({num: postnum});
 							PostLocationCommentStore.load({
		 						callback: function() {
 									Ext.getCmp('postlocationcommentText').reset();
 									Ext.Msg.alert('', '댓글이 등록되었습니다.', Ext.emptyFn);
 								}
							}); 			
 						}
 					});
 				}
    		}]
   		}]
	}
});

Ext.define('PostLocationCommentItem', {
	extend: 'Ext.dataview.component.DataItem',
    xtype: 'PostLocationCommentItem',
	config: {
		style: 'margin-left:-15px;',
		listeners: {
			initialize: function() {
				var writerid = this.getRecord().get('WriterID');
				
				var img = this.getItems().items[1];
				img.setSrc('https://graph.facebook.com/'+writerid+'/picture');
				
				var userid = UserStore.getAt(0).data.ID;
				var delbtn = this.getItems().items[2];
				if (userid == writerid) {
					delbtn.show();
				} else {
					Ext.emptyFn
				}
			}
		},
		layout: 'hbox',
		width: '105%',
		style: 'background:white;border-bottom:1px #CBCAC7 solid;margin-left:-17px',
		items: [
		{
			xtype: 'panel',
			style: 'word-break:break-all; padding-right:35px',
			tpl: '<a class="writer">{Writer}</a><br>{Text}<br><font size="2">{Date}&nbsp;&nbsp;&nbsp;&nbsp;{Time}</font>',
			listeners: {
				tap: {
					element: 'element',
					delegate: 'a.writer',
					fn: function() {
						var dataitem = this.getParent();
						var otherid = dataitem.getRecord().get('WriterID');
						openOtherinfo(otherid);
					}
				}
			}
		},
		{
			xtype: 'img',
			height: 64,
			width: 64,
			docked: 'left',
			listeners: {
				tap: function() {
					var dataitem = this.getParent();
					var otherid = dataitem.getRecord().get('WriterID');
					openOtherinfo(otherid)
				}
			}
		},
		{
			xtype: 'button',
			text: 'X',
			style: 'background:white;border:0px solid',
			width: 32,
			height: 32,
			docked: 'right',
			hidden: true,
			handler: function() {
				var dataitem = this.getParent();
				var commentnum = dataitem.getRecord().get('Number');
				var postnum = dataitem.getRecord().get('PostNumber');
				
				Ext.Msg.show({
  					title: '알림',
  					message: '삭제하시겠습니까?',
   		        	width: 300,
   					buttons:  [{
   						id: 'ok',
   						text: 'Ok',
   						ui: 'action'
   					},
   					{	
   						id: 'cancel',
   						text: 'Cancel'
   					}],   					
   					fn: function(buttonId) {
       					if (buttonId == 'Ok') {
       						Ext.data.JsonP.request({
 								url: 'http://itscreater.cafe24.com/Triends/PostCommentDelete.jsp',
 								params: {num: commentnum},
 								callbackkey: 'callback',
 								success: function() {
 									var PostLocationCommentStore = Ext.getStore('PostLocationCommentStore');
 									PostLocationCommentStore.getProxy().setExtraParams({num: postnum});
 									PostLocationCommentStore.load(); 			
 								}
 							});
						} else if (buttonId == 'Cancel') {
       						Ext.emptyFn
       					}
   					}
				});
			}
		}]
    }
});

Ext.define("Triends.Post",{
	extend: "Ext.data.Model",
	id: 'postlocationmodel',
	config: {
		idProperty: 'Number', //pullrefresh에서 중복된 값이 바인딩 되지 않도록 하기 위함!
		fields: ["Number", "ID", "WRITER", "TITLE", "CONTENT", "CONTINENT", "NATION", "DATE", "TIME", "HHMM"]
	}
});

var postLocationStore = Ext.create("Ext.data.Store",{
	model: "Triends.Post",
	id: 'postlocationstore',
	pageSize: 10,
	clearOnPageLoad: false,
//	proxy: {
//		type: "jsonp",
//		url: 'http://itscreater.cafe24.com/Triends/PostLocationList.jsp', // 속도 느릴 경우 proxy제거 
//		callbackkey: 'callback',
//		reader: {
//			type: "json",
//			root: "data"
//		}
//	},
	sorters: [
		{
			property: 'DATE',
			direction: 'DESC'
		},
		{
			property: 'TIME',
			direction: 'DESC'
		}
	]
});



Ext.define('Triends.view.PostLocationList', {
	extend: 'Ext.dataview.List',
	xtype: 'postlocationlist',
	id: 'postlocationlist',
	requires: ['Triends.view.LocationField1','Triends.view.SearchOverlay', 'Ext.plugin.ListPaging', 'Ext.plugin.PullRefresh'],
	config: {
		plugins: [
				{type: 'listpaging', autoPaging:true, clearOnPageLoad: false, loadMoreText: 'Next..'},
				{type: 'pullrefresh' /*refreshFn: function(plugin){postStore.load()}*/}
		],
		fullscreen: true,
		disableSelection: true,
		limit: 10,
		pressedCls: "x-item-selected",
		selectedCls: "",
		pressedDelay: 50,
		hidden: true,
		store: postLocationStore,
		itemTpl: "<b>{TITLE}</b><br><font size='2'>{WRITER}&nbsp;&nbsp;|&nbsp;&nbsp;{DATE}&nbsp;&nbsp;&nbsp;{HHMM}</font>",
		listeners: {
	        itemtap: function(list, index, target, model, e, eOpts) {
	        	
	        	
	        	try {
	        		var userid = Ext.getStore('UserStore').getAt(0).data.ID;
	        		if (model.data.ID == userid) {
	        		//Postinfo 삭제가능	
	        		var postdelbtn = Ext.getCmp('postlocationdeletebtn');
	        		var postmdfbtn = Ext.getCmp('postlocationmodifybtn');
	        		postdelbtn.setHidden(false);
	        		postmdfbtn.setHidden(false);
		        	} else {
		        		//Postinfo 삭제불가능
		        		var postdelbtn = Ext.getCmp('postlocationdeletebtn');
		        		var postmdfbtn = Ext.getCmp('postlocationmodifybtn');
		        		postdelbtn.setHidden(true);
		        		postmdfbtn.setHidden(true);
		        	}
	        	
		        	var postlocationtitlepanel1 = Ext.getCmp('postlocationtitlepanel1');
		        	var postlocationtitlepanel2 = Ext.getCmp('postlocationtitlepanel2');
		        	var postlocationcontentpanel = Ext.getCmp('postlocationcontentpanel');
		        	postlocationcontentpanel.setData(model.data);
		        	postlocationtitlepanel1.setData(model.data);
		        	postlocationtitlepanel2.setData(model.data);
		        	
		        	var PostLocationCommentStore = Ext.getStore('PostLocationCommentStore');
	 					PostLocationCommentStore.getProxy().setExtraParams({num: model.getData().Number});
	 					PostLocationCommentStore.load({
	 						callback: function() {
								Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            						url: 'mainpage/post/postinfolocation'
	        					}));		 	
	        				}
						}); 
	        	} catch(e){
	        		Ext.Msg.alert("","로그인이 필요합니다");
	        	}
	        }
	    },
		items: [
			{
			xtype: 'toolbar',
			docked: 'top',
			items: [
			{
				xtype: 'button',
				text: '지역검색',
				height: '20px',
				id: 'locationbutton',
				iconCls: 'maps',
				iconMask: true,
				handler: function(btn){				
					var locationOverlay = Ext.create("Triends.view.LocationOverlay");
					Ext.Viewport.add(locationOverlay);
				}
			},
			{
				xtype: 'spacer'
			},
			{
				xtype: 'button',
				id: 'locationsearchbutton',
				text: '검색',
				height: '20px',
				iconCls: 'search',
				iconMask: true,
				handler: function(btn){
					var searchoverlay = Ext.getCmp("searchoverlay");
					var searchaction = Ext.getCmp("searchaction");
					var postsearch = Ext.getCmp("postsearch");
					//로컬 스토리지 사용check
					var continent = localStorage.continent;
					var nation = localStorage.nation;
					// modal action 적용하기
					searchoverlay.showBy(btn);
					searchaction.addListener({
						tap: function(){
							var searchValue = Ext.getCmp("postsearch").getValue(); //listener밖에 두면 안된다!!!
							postLocationStore.removeAll();
							postLocationStore.setProxy({
								type: "jsonp",
								url: 'http://itscreater.cafe24.com/Triends/PostLocationSearch.jsp',
								extraParams: {searchvalue: searchValue, continent: continent, nation: nation},
								callbackkey: 'callback',
								pageParam: 'pages',
								limitParam: 'rpp',
								reader: {
									type: "json",
									rootProperty: "results",
									totalProperty: "total"
								}	
							})
							postLocationStore.loadPage(1);
//							Ext.data.JsonP.request({
//								url: 'http://itscreater.cafe24.com/Triends/PostLocationSearch.jsp',
//								params: {searchvalue: searchValue, continent: continent, nation: nation},
//								callbackkey: 'callback',
//								success: function(result){
//									postLocationStore.setData(result);
//									postsearch.reset();
//									searchoverlay.hide();
//								}
//							})
						}
					})
				}
			},
			{
				xtype: 'button',
				id: 'locationwritebutton',
				text: '글쓰기',
				height: '20px',
				iconCls: 'compose',
				iconMask: true,
				handler: function() {
					try{
						var userid = Ext.getStore("UserStore").getAt(0).data.ID;
			        	Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            				url: 'mainpage/post/postinglocation'
	        			}));	
					} catch(e){
						Ext.Msg.alert("","로그인이 필요합니다");
					}
				}
		}]
		}
		]
		
	}
});

Ext.define('Triends.view.PostLocationModify', {
	extend: 'Ext.form.Panel',
 	id: 'postlocationmodify',
	xtype: 'postlocationmodify',
	config:{
	fullscreen: true,
	showAnimation: 'slideIn',
	listeners: {
 		deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
				Ext.getCmp('titlelocationmodify').reset();
				Ext.getCmp('contentlocationmodify').reset();
				Ext.getCmp("continent3").reset();
 				Ext.getCmp("nation3").reset();
 			}
 	},
 	items: [
 		{
 			xtype: 'locationfield3'
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Title',
 			items: [{
 				xtype: 'textfield',
 				name: 'title',
 				style: 'border:3px inset',
 				id: 'titlelocationmodify'
 			}]
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Content',
 			items: [{
 				xtype: 'textareafield',
 				name: 'content',
 				minHeight: 200,
 				style: 'border:3px inset',
 				id: 'contentlocationmodify'
 			}]
 		},
 		{
 			xtype: 'button',
 			text: '등록',
 			style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 	width: '100%',
 			handler: function(){
 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
 				
 				var postinfopanel = Ext.getCmp("postinfolocationpanel");
 				var num = postinfopanel.getData().Number;
 				
 				var titlefield = Ext.getCmp('titlelocationmodify');
 				var contentfield = Ext.getCmp('contentlocationmodify');
 				var continentfield = Ext.getCmp("continent3");
 				var nationfield = Ext.getCmp("nation3");
 				var post = Ext.getCmp('post');
 				Ext.Ajax.request({
 					url: 'http://itscreater.cafe24.com/Triends/PostModify.jsp',
 					params: {
 						num: num, 
 						title: titlefield.getValue(), 
 						content: contentfield.getValue(),
 						continent: continentfield.getValue(),
 						nation: nationfield.getValue()
 					},
// 					callbackkey: 'callback',
 					success: function(response) {
 						Ext.Msg.alert('', '글이 수정되었습니다.', Ext.emptyFn);
 						
 						postLocationStore.setProxy({
							type: "jsonp",
							url: 'http://itscreater.cafe24.com/Triends/PostLocationList.jsp',
							extraParams: {continent: continentfield.getValue(),
										  nation: nationfield.getValue()},
							callbackkey: 'callback',
							pageParam: 'pages',
							limitParam: 'rpp',
							reader: {
								type: "json",
								rootProperty: "results",
								totalProperty: "total"
							}
						})
						postLocationStore.loadPage(1);
 						
						localStorage.removeItem(continent);
						localStorage.removeItem(nation);
						localStorage.setItem("continent", continentfield.getValue());
						localStorage.setItem("nation", nationfield.getValue());
 						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage'
        					}));
        				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage/post/postlocationlist'
        					}));
 					}
 				});
 			}	
 		}]
	}
});

Ext.define('Triends.view.PostLocationModify', {
	extend: 'Ext.form.Panel',
 	id: 'postlocationmodify',
	xtype: 'postlocationmodify',
	config:{
	fullscreen: true,
	showAnimation: 'slideIn',
	listeners: {
 		deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
				Ext.getCmp('titlelocationmodify').reset();
				Ext.getCmp('contentlocationmodify').reset();
				Ext.getCmp("continent3").reset();
 				Ext.getCmp("nation3").reset();
 			}
 	},
 	items: [
 		{
 			xtype: 'locationfield3'
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Title',
 			items: [{
 				xtype: 'textfield',
 				name: 'title',
 				style: 'border:3px inset',
 				id: 'titlelocationmodify'
 			}]
 		},
 		{
 			xtype: 'fieldset',
 			title: 'Content',
 			items: [{
 				xtype: 'textareafield',
 				name: 'content',
 				minHeight: 200,
 				style: 'border:3px inset',
 				id: 'contentlocationmodify'
 			}]
 		},
 		{
 			xtype: 'button',
 			text: '등록',
 			style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 	width: '100%',
 			handler: function(){
 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
 				
 				var postinfopanel = Ext.getCmp("postinfolocationpanel");
 				var num = postinfopanel.getData().Number;
 				
 				var titlefield = Ext.getCmp('titlelocationmodify');
 				var contentfield = Ext.getCmp('contentlocationmodify');
 				var continentfield = Ext.getCmp("continent3");
 				var nationfield = Ext.getCmp("nation3");
 				var post = Ext.getCmp('post');
 				Ext.Ajax.request({
 					url: 'http://itscreater.cafe24.com/Triends/PostModify.jsp',
 					params: {
 						num: num, 
 						title: titlefield.getValue(), 
 						content: contentfield.getValue(),
 						continent: continentfield.getValue(),
 						nation: nationfield.getValue()
 					},
// 					callbackkey: 'callback',
 					success: function(response) {
 						Ext.Msg.alert('', '글이 수정되었습니다.', Ext.emptyFn);
 						
 						postLocationStore.setProxy({
							type: "jsonp",
							url: 'http://itscreater.cafe24.com/Triends/PostLocationList.jsp',
							extraParams: {continent: continentfield.getValue(),
										  nation: nationfield.getValue()},
							callbackkey: 'callback',
							pageParam: 'pages',
							limitParam: 'rpp',
							reader: {
								type: "json",
								rootProperty: "results",
								totalProperty: "total"
							}
						})
						postLocationStore.loadPage(1);
 						
						localStorage.removeItem(continent);
						localStorage.removeItem(nation);
						localStorage.setItem("continent", continentfield.getValue());
						localStorage.setItem("nation", nationfield.getValue());
 						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage'
        					}));
        				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage/post/postlocationlist'
        					}));
 					}
 				});
 			}	
 		}]
	}
});

Ext.define('Triends.view.PostMain',{
	extend: 'Ext.Panel',
	xtype: 'postmain',
	id: 'postmain',
	config:{
		fullscreen: true,
    	layout: 'card',
    	showAnimation: 'slideIn',
    	listeners:{
    		initialize:function(){
    			var postStore = Ext.getStore('poststore');
		    				postStore.load();
    		}
    	},
    	items:[
    		{
				xtype: 'toolbar',
				docked: 'top',
				layout: 'hbox',
				height: '20%',
				items: [{
					xtype: 'segmentedbutton',
					width: '105%',
					style: 'margin-left:-2%',
					layout: 'hbox',
					items: [{
						text: '지역게시판',
						id: 'locationBtn1',
						flex: 1,
						handler: function(){
//		    				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
//		            			url: 'mainpage/post/postlocationlist'
//			        		}));
							var postlocationStore = Ext.getStore("postlocationstore");
		    				postlocationStore.load(); /* 원래 목록 뜰 수 있도록 */
							Ext.getCmp('postnormallist').hide();
							Ext.getCmp('postlocationlist').show();
		    				
						}
					},
					{
						text: '일반게시판',
						id: 'normalBtn1',
						pressed: true,
						flex: 1,
						handler:function(){
//		    				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
//		            			url: 'mainpage/post/postnormallist'
//			        		}));
							var postStore = Ext.getStore('poststore');
		    				postStore.load();
							Ext.getCmp('postlocationlist').hide();
							Ext.getCmp('postnormallist').show();
		    				
						}
					}]
				}]
			},
			{
				xtype: 'postnormallist'
			},
			{
				xtype: 'postlocationlist'
			}
    	]
	}
})

Ext.define("Triends.Model.PostNormalComment",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"Number", "PostNumber", "WriterID", "Writer", "Text", "Date", "Time"
		]
	}
});

var PostNormalCommentStore = Ext.create("Ext.data.Store",{
	model: "Triends.Model.PostNormalComment",
	id: 'PostNormalCommentStore',
	proxy: {
		type: "jsonp",
		callbackKey: 'callback',
		url: "http://itscreater.cafe24.com/Triends/PostCommentList.jsp"
	},
	sorters: [
		{
			property: 'Date',
			direction: 'ASC'
		},
		{
			property: 'Time',
			direction: 'ASC'
		}
	]
});

Ext.define('Triends.view.PostNormalComment', {
	extend: 'Ext.dataview.DataView',
	xtype: 'postnormalcomment',
	id: 'postnormalcomment',
	config: {
 		minHeight: 100,
 		style: 'margin-top:10px;',
 		width:'100%',
 		scrollable: false,
 		styleHtmlContent: true, // 이게 있으면 CSS가 제대로 안먹을수도, 없으면 하이퍼링크 안걸림
 		store: PostNormalCommentStore,
		useComponents: true,
		defaultType: 'PostNormalCommentItem',
		items: [{
    		xtype: 'panel',
    		docked: 'bottom',
    		layout: 'hbox',
    		style: "padding-right:15px",
    		items: [{
    			xtype: 'textfield',
    			id: 'postnormalcommentText',
    			style: 'height: 30px; font-size: 70%; padding: 0px;margin-top:3px;',
   				flex: 9
    		},
    		{
    			xtype: 'button',
    			iconCls: 'compose',
    			iconMask: true,
    			width: 50,
    			flex: 1,
    			handler: function() {
    				var thisview = Ext.getCmp('postinfopanel1');
	        		var postnum = thisview.getData().Number;
		    		var userid = Ext.getStore('UserStore').getAt(0).data.ID;
		    		var username = Ext.getStore('UserStore').getAt(0).data.Name;
		    		var text = Ext.getCmp('postnormalcommentText').getValue();
		    		
		    		Ext.Ajax.request({
 						url: 'http://itscreater.cafe24.com/Triends/PostCommentWrite.jsp',
 						params: {
 							id: userid, 
 							name: username,
 							num: postnum, 
 							text: text
 						},
 						success: function(response) {
 							var PostNormalCommentStore = Ext.getStore('PostNormalCommentStore');
 							PostNormalCommentStore.getProxy().setExtraParams({num: postnum});
 							PostNormalCommentStore.load({
		 						callback: function() {
 									Ext.getCmp('postnormalcommentText').reset();
 									Ext.Msg.alert('', '댓글이 등록되었습니다.', Ext.emptyFn);
 								}
							}); 			
 						}
 					});
 				}
    		}]
   		}]
	}
});

Ext.define('PostNormalCommentItem', {
	extend: 'Ext.dataview.component.DataItem',
    xtype: 'PostNormalCommentItem',
	config: {
		style: 'margin-left:-15px;',
		listeners: {
			initialize: function() {
				var writerid = this.getRecord().get('WriterID');
				var img = this.getItems().items[1];
				img.setSrc('https://graph.facebook.com/'+writerid+'/picture');
				var userid = UserStore.getAt(0).data.ID;
				var delbtn = this.getItems().items[2];
				if (userid == writerid) {
					delbtn.show();
				} else {
					Ext.emptyFn
				}
			}
		},
		layout: 'hbox',
		width: '105%',
		style: 'background:white;border-bottom:1px #CBCAC7 solid;margin-left:-17px',
		items: [
		{
			xtype: 'panel',
			style: 'word-break:break-all; padding-right:35px',
			tpl: '<a class="writer">{Writer}</a><br>{Text}<br><font size="2">{Date}&nbsp;&nbsp;&nbsp;&nbsp;{Time}</font>',
			listeners: {
				tap: {
					element: 'element',
					delegate: 'a.writer',
					fn: function() {
						var dataitem = this.getParent();
						var otherid = dataitem.getRecord().get('WriterID');
						
						openOtherinfo(otherid);
					}
				}
			}
		},
		{
			xtype: 'img',
			height: 64,
			width: 64,
			docked: 'left',
			listeners: {
				tap: function() {
					var dataitem = this.getParent();
					var otherid	= dataitem.getRecord().get('WriterID');
					openOtherinfo(otherid);
				}
			}
		},
		{
			xtype: 'button',
			text: 'X',
			width: 32,
			style: 'background:white;border:0px solid',
			height: 32,
			docked: 'right',
			hidden: true,
			handler: function() {
				var dataitem = this.getParent();
				var commentnum = dataitem.getRecord().get('Number');
				var postnum = dataitem.getRecord().get('PostNumber');
				
				Ext.Msg.show({
  					title: '알림',
  					message: '삭제하시겠습니까?',
   		        	width: 300,
   					buttons:  [{
   						id: 'ok',
   						text: 'Ok',
   						ui: 'action'
   					},
   					{	
   						id: 'cancel',
   						text: 'Cancel'
   					}],   					
   					fn: function(buttonId) {
       					if (buttonId == 'Ok') {
       						Ext.data.JsonP.request({
 								url: 'http://itscreater.cafe24.com/Triends/PostCommentDelete.jsp',
 								params: {num: commentnum},
 								callbackkey: 'callback',
 								success: function() {
 									var PostNormalCommentStore = Ext.getStore('PostNormalCommentStore');
 									PostNormalCommentStore.getProxy().setExtraParams({num: postnum});
 									PostNormalCommentStore.load(); 
 								}
 							});
						} else if (buttonId == 'Cancel') {
       						Ext.emptyFn
       					}
   					}
				});
			}
		}]
    }
});

Ext.define("Triends.Post",{
	extend: "Ext.data.Model",
	config: {
		idProperty: 'Number', //pullrefresh에서 중복된 값이 바인딩 되지 않도록 하기 위함!
		fields: ["Number", "ID", "WRITER", "TITLE", "CONTENT", "CONTINENT", "NATION", "DATE", "TIME", "HHMM"]
	}
});

var postStore = Ext.create("Ext.data.Store",{
	model: "Triends.Post",
	id: 'poststore',
	pageSize: 10,
	clearOnPageLoad: false,
	proxy: {
		type: "jsonp",
		url: 'http://itscreater.cafe24.com/Triends/Postlist.jsp',
		callbackkey: 'callback',
		pageParam: 'pages',
		limitParam: 'rpp',
		reader: {
			type: "json",
			rootProperty: "results",
			totalProperty: "total"
		}	
	},
	sorters: [
		{
			property: 'DATE',
			direction: 'DESC'
		},
		{
			property: 'TIME',
			direction: 'DESC'
		}
	]
});


Ext.define('Triends.view.PostNormalList', {
	requires: ['Triends.view.SearchOverlay', 'Ext.plugin.ListPaging', 'Ext.plugin.PullRefresh'],
	extend: 'Ext.dataview.List',
	xtype: 'postnormallist',
	id: 'postnormallist',
	config: {
		plugins: [
			{type: 'listpaging', autoPaging:true, clearOnPageLoad: false, loadMoreText: 'Next..'},
			{type: 'pullrefresh' /*refreshFn: function(plugin){postStore.load()}*/}
		],
		fullscreen: true,
		store: postStore,
		limit: 10,
		hidden: true,
		pressedCls: "x-item-selected",
		selectedCls: "",
		pressedDelay: 50,
		itemTpl: "<b>{TITLE}</b><br><font size='2'>{WRITER}&nbsp;&nbsp;|&nbsp;&nbsp;{DATE}&nbsp;&nbsp;&nbsp;{HHMM}</font>",
		listeners: 
			{
				itemtap: function(list, index, target, model, e, eOpts) {
	        	 //logout버튼으로 login후에 사용가능
	        	try {
	        		
	        		var userid = Ext.getStore('UserStore').getAt(0).data.ID;
	        		var postnum = model.getData().Number;
	        		
		        	if (model.data.ID == userid) {
		        		//Postinfo 수정, 삭제가능
		        		var postdelbtn = Ext.getCmp('postnormaldeletebtn');
		        		var postmdfbtn = Ext.getCmp('postnormalmodifybtn');
		        		postdelbtn.setHidden(false);
		        		postmdfbtn.setHidden(false);
		        		
		        	} else {
		        		//Postinfo 수정, 삭제불가능
		        		var postdelbtn = Ext.getCmp('postnormaldeletebtn');
		        		var postmdfbtn = Ext.getCmp('postnormalmodifybtn');
		        		postdelbtn.setHidden(true);
		        		postmdfbtn.setHidden(true);
		        	}
		        	var postnormallist = Ext.getCmp("postnormallist");
		        	var postinfopanel1 = Ext.getCmp('postinfopanel1');
		        	var postinfopanel2 = Ext.getCmp('postinfopanel2');
		        	var postcontentpanel = Ext.getCmp('postcontentpanel');
		        	postinfopanel1.setData(model.data);
		        	postinfopanel2.setData(model.data);
		        	postcontentpanel.setData(model.data);
		        					
		        	var PostNormalCommentStore = Ext.getStore('PostNormalCommentStore');
	 					PostNormalCommentStore.getProxy().setExtraParams({num: postnum});
	 					PostNormalCommentStore.load({
	 						callback: function() {
								Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            						url: 'mainpage/post/postinfo'
	        					}));					        	
	 						}
						}); 
	        	} catch(e){
	        		Ext.Msg.alert("","로그인이 필요합니다");
	        	}	        	
	        },
	        
	        initialize: function(){
				var postStore = Ext.getStore('poststore');
				postStore.load();
			}
	    },
		items: [
			{
			xtype: 'toolbar',
			docked: 'top',
			items: [
			{
				xtype: 'spacer'
			},
			{
				xtype: 'button',
				id: 'searchbutton',
				text: '검색',
				height: '20px',
				iconCls: 'search',
				iconMask: true,
				handler: function(btn){
					var searchoverlay = Ext.getCmp("searchoverlay");
					searchoverlay.showBy(btn);
				}	
			},
			{
				xtype: 'button',
				id: 'writebutton',
				text: '글쓰기',
				height: '20px',
				iconCls: 'compose',
				iconMask: true,
				handler: function() {
					try{
						var userid = Ext.getStore("UserStore").getAt(0).data.ID;
						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            						url: 'mainpage/post/postingnormal'
	        					}));	
					} catch(e){
						Ext.Msg.alert("","로그인이 필요합니다");
					}
				}
			}]
		}]
		
	}
});

Ext.define('Triends.view.PostNormalModify', {
	extend: 'Ext.form.Panel',
 	id: 'postnormalmodify',
	xtype: 'postnormalmodify',
	config:{
	fullscreen: true,
	showAnimation: 'slideIn',
	listeners: {
 		deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
				Ext.getCmp('titlemodify').reset();
				Ext.getCmp('contentmodify').reset();
 			}
 	},
 	items: [{
 			xtype: 'fieldset',
 			title: '제목',
 			items: [{
 				xtype: 'textfield',
 				name: 'title',
 				style: 'border:3px inset',
 				id: 'titlemodify'
 			}]
 		},
 		{
 			xtype: 'fieldset',
 			title: '내용',
 			items: [{
 				xtype: 'textareafield',
 				name: 'content',
 				minHeight: 300,
 				style: 'border:3px inset',
 				id: 'contentmodify'
 			}]
 		},
 		{
 			xtype: 'button',
 			text: '등록',
 			style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 	width: '100%',
 			handler: function(){
 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
 				
 				var postinfopanel = Ext.getCmp("postinfopanel");
 				var num = postinfopanel.getData().Number;
 				
 				var titlefield = Ext.getCmp('titlemodify');
 				var contentfield = Ext.getCmp('contentmodify');
 				var post = Ext.getCmp('post');
 				Ext.Ajax.request({
 					url: 'http://itscreater.cafe24.com/Triends/PostModify.jsp',
 					params: {
 						num: num, 
 						title: titlefield.getValue(), 
 						content: contentfield.getValue()
 					},
 					success: function(response) {
 						Ext.Msg.alert('', '글이 수정되었습니다.', Ext.emptyFn);
 						
 						var postStore = Ext.getStore('poststore');
 						postStore.loadPage(1);
 						
 						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage'
        					}));
        				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage/post/postnormallist'
        					}));
 					}
 				});
 			}	
 		}]
	}
});

 Ext.define('Triends.view.PushPage', {
 	extend: 'Ext.Panel',
 	xtype: 'pushpage',
 	id: 'pushpage',
 	config: {
 		fullscreen: true,
 		layout: 'vbox',
 		scrollable: false,
 		style: 'background:white',
 		items: [
 		{
	   		xtype: 'panel',
	   		docked: 'top',
	   		height: 30,
	   		style: {'padding-top':'3px','padding-left':'27px','background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))'},
	   		html: '<b>Push</b>'
	   	},{
			xtype: 'formpanel',
			flex: 1,
			id: 'pushform',
			items: [{
				xtype: 'fieldset',
				items: [{
					xtype: 'checkboxfield',
	            	id : 'pushnoti',
	            	name: 'pushnoti',
	            	label: 'Push알림',
	            	listeners: {
						check: function(){
							var UserStore = Ext.getStore('UserStore');
			    			var userid = UserStore.getAt(0).data.ID;
							var pushnoti = 1;
							Ext.data.JsonP.request({
							   	url: 'http://itscreater.cafe24.com/Triends/gcmmodify.jsp',
							   	params: {
							   		id: userid,
							   		push: pushnoti
							  	},
							   	callbackKey: 'callback',
							   	success: function() {
							   		Ext.Msg.alert('', '변경되었습니다.', Ext.emptyFn);
							   	}
							});
						},
						uncheck: function() {
							Ext.getCmp('vibratenoti').setChecked(false);
							var UserStore = Ext.getStore('UserStore');
			    			var userid = UserStore.getAt(0).data.ID;
							var pushnoti = 0;
							Ext.data.JsonP.request({
							   	url: 'http://itscreater.cafe24.com/Triends/gcmmodify.jsp',
							   	params: {
							   		id: userid,
							   		push: pushnoti
							  	},
							   	callbackKey: 'callback',
							   	success: function() {
							   		Ext.Msg.alert('', '변경되었습니다.', Ext.emptyFn);
							   	}
							});
						}
	            	}
				},
				{
	            	xtype: 'checkboxfield',
	            	id : 'vibratenoti',
	            	name: 'vibratenoti',
	            	label: '진동알림',
	            	listeners: {
						check: function() {
							Ext.getCmp('pushnoti').setChecked(true);
							var UserStore = Ext.getStore('UserStore');
			    			var userid = UserStore.getAt(0).data.ID;	
			    			var vibratenoti = 1; 
							Ext.data.JsonP.request({
							   	url: 'http://itscreater.cafe24.com/Triends/gcmmodify.jsp',
							   	params: {
							   		id: userid,
							   		vibrate: vibratenoti
							  	},
							   	callbackKey: 'callback',
							   	success: function() {
							   		Ext.Msg.alert('', '변경되었습니다.', Ext.emptyFn);
							   	}
							});
						},
						uncheck:function(){
							var UserStore = Ext.getStore('UserStore');
			    			var userid = UserStore.getAt(0).data.ID;	
			    			var vibratenoti = 0; 
							Ext.data.JsonP.request({
							   	url: 'http://itscreater.cafe24.com/Triends/gcmmodify.jsp',
							   	params: {
							   		id: userid,
							   		vibrate: vibratenoti
							  	},
							   	callbackKey: 'callback',
							   	success: function() {
							   		Ext.Msg.alert('', '변경되었습니다.', Ext.emptyFn);
							   	}
							});
						}
	            	}
		   		}]
        	}]
	   	}]
 	}
 });
 
  Ext.define('Triends.view.QuestionPage', {
 	extend: 'Ext.Panel',
 	xtype: 'questionpage',
 	id: 'questionpage',
 	config: {
 		fullscreen: true,
 		layout: 'vbox',
 		scrollable: false,
 		style: 'background:white',
 		items: [
 		{
	   		xtype: 'panel',
	   		docked: 'top',
	   		height: 30,
	   		style: {'margin-bottom':'20px','padding-top':'3px','padding-left':'27px','background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))'},
	   		html: '<b>Question</b>'
	   	},
	   	{
	   		xtype: 'spacer',
	   		flex:1
	   	},
	   	{
 			xtype: 'panel',
 			flex:1,
	 		html: 
	 				'<p align="center"><font size="2"><font size="3"><b>Triends</b></font>는 단 것과 쓴 것 모두 가리지 않습니다.</font></p>' +
	 			'<p align="center"><font size="2"><font size="3"><b>Triends</b></font>는 항상 여러분들에게 눈과 귀를 열어놓겠습니다.</font></p><br><br>' +
	 				' <p align="center"><font size="5"><b>info@triends.co.kr</b></font></p>'
 		},
 		{
	   		xtype: 'spacer',
	   		flex:1
	   	}]
 	}
 });
 
 Triends.view.SearchOverlay = Ext.create('Ext.Panel',{
	id: 'searchoverlay',
	layout: 'fit',
	hideOnMaskTap: true,
	scrollable: false,
	modal: true,
	centered: true,
	width: 330,
	height: 80,
	items: [
		{
			xtype: 'toolbar',
			items:[
				{
					xtype: 'searchfield',
					id: 'postsearch',
					placeHolder: 'Input Keywords',
					autocomplete: true,
					autoCreateField: true	
				},
				{
					xtype: 'button',
					id: 'searchaction',
					height: '20px',
					iconCls: 'search',
					iconMask: true,
					handler: function(){
						var searchValue = Ext.getCmp("postsearch").getValue();
						var postStore = Ext.getStore('poststore');
						var searchoverlay = Ext.getCmp("searchoverlay");
						var postsearch = Ext.getCmp("postsearch");
						Ext.data.JsonP.request({
							url: 'http://itscreater.cafe24.com/Triends/PostSearch.jsp',
							params: {searchvalue: searchValue},
							callbackkey: 'callback',
							success: function(result){
								postStore.setData(result)
								postsearch.reset();
								searchoverlay.hide();
							}
						})
					}
				}
			]
		}
	]
})

Ext.define('Triends.view.Sendmessage', {
	extend: 'Ext.Panel',
	xtype: 'sendmessage',
	id: 'send',
	config: {
    	modal: true,
    	top: '10%',
    	left: '50%',
    	layout: 'vbox',
    	style: 'margin-left:-150px',
		hideOnMaskTap: true,
		width: 300,
		height: 350,
		listeners: {
			hide: function() {
				this.destroy();
			}
		},
//		hidden: true,
    	items: [{
    		xtype: 'titlebar',
    		docked: 'top',
    		height: 50,
    		title: 'Message'
    	},
    	{
    		xtype: 'panel',
    		docked: 'top',
    		height: 40,
    		style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
    		items:[{
    			id: 'getterpanel',
    			xtype: 'panel',
    			padding: 5,
	    		tpl: [
					"<font size='2'><b>받는 사람 :&nbsp;&nbsp;{Getter}</b></font>" //ID대신 OtherName필요합니다.
				]
    		}]
    	},
    	{
    		xtype: 'panel',
    		height: 210,
    		items: [{
	    		xtype: 'textareafield',
	    		height: 220,
	    		maxRows: 8,
	    		id: 'msgcontents'
    		}]
    	},
    	{
    		xtype: 'button',
    		docked: 'bottom',
    		text: 'send',
    		handler: function() {
    			var senderID = Ext.getCmp('send').getData().SenderID;
    			var sender = Ext.getCmp('send').getData().Sender;
    			var getterID = Ext.getCmp('send').getData().GetterID;
    			var getter = Ext.getCmp('send').getData().Getter;
    			var msg = Ext.getCmp('msgcontents').getValue();
    			
    			Ext.Ajax.request({
            		url: 'http://itscreater.cafe24.com/Triends/Sendmessage.jsp',
            		useDefaultXhrHeader: false,
            		params: {
            			senderID: senderID,
            			sender: sender,
            			getterID: getterID,
            			getter: getter,
            			msg : msg
            		},
            		reader: {type: 'json'},
//            		callbackKey: 'callback',
            		success: function(response) {
//            					var result = Ext.JSON.decode(response.responseText);
            					console.log(response.responseText);
            			//MessageStore.load(); // 보낸쪽지함 있을 시 살려야함
           						var send = Ext.getCmp('send');
    							send.destroy();
    							Ext.Msg.alert('', '전송되었습니다.', Ext.emptyFn);
    							
            		}
            	});
    			
//    			Ext.data.JsonP.request({
//            		url: 'http://itscreater.cafe24.com/Triends/Sendmessage.jsp',
//            		params: {
//            			senderID: senderID,
//            			sender: sender,
//            			getterID: getterID,
//            			getter: getter,
//            			msg : msg
//            		},
//            		callbackKey: 'callback',
//            		success: function() {
//            					//MessageStore.load(); // 보낸쪽지함 있을 시 살려야함
//           						var send = Ext.getCmp('send');
//    							send.destroy();
//    							Ext.Msg.alert('', '전송되었습니다.', Ext.emptyFn);
//            		}
//            	});
            	
    		}
    	}]
	}
});

Ext.define('Triends.view.Settings', {
	extend: 'Ext.Panel',
	xtype: 'settingslist',
	id: 'settingslist',
	config: {
		showAnimation: 'slideIn',
	   	items: [{
	   		xtype: 'panel',
	   		docked: 'top',
	   		height: 30,
	   		style: {'margin-bottom':'20px','padding-top':'3px','padding-left':'25px','background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))'},
	   		html: '<b>Information</b>'
	   	},
	   	{
	   		xtype: 'list',
	   		scrollable: false,
	   		margin: 10,
	   		pressedCls: "x-item-selected",
			selectedCls: "",
			pressedDelay: 50,
 			style: 'background:white;',
 			store: {
	 			fields: ["name", "number"],
	 			data: [
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>버전정보</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'versionpage'},
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>공지사항</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'noticelist'},
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>도움말</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'helppage'},
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>문의 / 건의</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'questionpage'},
					{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>Push설정</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'pushpage'}]
 			},
		   	itemTpl: '{name}',
		   	listeners: {
		   		itemtap: function(list, index, target, model, e, eOpts) {
		   			if (model.data.id == 'noticelist') {
		   				var noticestore = Ext.getStore('noticestore');
		   				noticestore.load({
		   					callback: function() {
		   						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            					url: 'mainpage/settings/'+model.data.id
		        				}));
		   					}
		   				})
		   			} else if (model.data.id == 'pushpage') {
		   				var UserStore = Ext.getStore('UserStore');
			    		var userid = UserStore.getAt(0).data.ID;

			    		Ext.data.JsonP.request({
				   			url: 'http://itscreater.cafe24.com/Triends/gcmcheck.jsp',
				   			params: {
				   				id: userid
				   			},
				   			callbackKey: 'callback',
				   			success: function(result) {
				   				if (result.push == 1) {
				   					Ext.getCmp('pushnoti').setChecked(true);
				   				} else if (result.push == 0){
				   					Ext.getCmp('pushnoti').setChecked(false);
				   					Ext.getCmp('vibratenoti').setChecked(false);
				   				}
				   				
				   				if (result.vibrate == 1) {
				   					Ext.getCmp('vibratenoti').setChecked(true);
				   					Ext.getCmp('pushnoti').setChecked(true);
				   				} else if (result.vibrate == 0) {
				   					Ext.getCmp('vibratenoti').setChecked(false);
				   				}
				   				
				   				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            					url: 'mainpage/settings/'+model.data.id
		        				}));
				   			}
						});		   			
		   			} else {
		   				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            					url: 'mainpage/settings/'+model.data.id
		        				}));
		   			}
			    	
		   		}
		   	}
	   	}]
	}
});

Ext.define("Triends.Model.TingComment",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"Number", "TingNumber", "WriterID", "Writer", "Text", "Date", "Time"
		]
	}
});

Ext.define('Triends.view.TingComment', {
	extend: 'Ext.dataview.DataView',
	xtype: 'tingcomment',
	id: 'tingcomment',
	config: {
 		minHeight: 100,
 		style: 'margin-top:10px;',
 		width:'100%',
 		scrollable: false,
 		styleHtmlContent: true, // 이게 있으면 CSS가 제대로 안먹을수도, 없으면 하이퍼링크 안걸림
 		useComponents: true,
		defaultType: 'TingCommentItem',
	   	items: [{
    		xtype: 'panel',
    		docked: 'bottom',
    		layout: 'hbox',
    		style: "padding-right:15px",
    		items: [{
    			xtype: 'textfield',
    			id: 'tingcommentText',
   				flex: 9,
   				style: 'height: 30px; font-size: 70%; padding: 0px;margin-top:3px;' // font-size를 줄여줘야 전체 textfield의 height도 줄어든다
    		},
    		{
    			xtype: 'button',
    			iconCls: 'compose',
    			iconMask: true,
    			width: 50,
    			flex: 1,
    			handler: function() {
	    				var hostpanel = Ext.getCmp("hostpanel");
			    		var tingnum = hostpanel.getData().NUMBER;
			    		var userid = Ext.getStore('UserStore').getAt(0).data.ID;
			    		var username = Ext.getStore('UserStore').getAt(0).data.Name;
			    		var TingCommentStore = Ext.getStore('TingCommentStore'+tingnum);
			    		
			    		var text = Ext.getCmp('tingcommentText').getValue();
			    		
			    		Ext.Ajax.request({
	 						url: 'http://itscreater.cafe24.com/Triends/TingCommentWrite.jsp',
	 						params: {
	 							id: userid,
	 							name: username,
	 							num: tingnum, 
	 							text: text
	 						},
	 						success: function(response){
	 							var result = Ext.JSON.decode(response.responseText);
            					console.log(result.error);
	 							Ext.data.JsonP.request({
	            					url: 'http://itscreater.cafe24.com/Triends/TingCommentList.jsp',
	            					params: {num: tingnum},
	            					callbackKey: 'callback',
	            					success: function(result) {
										TingCommentStore.removeAll();
										TingCommentStore.add(result);
										var TingComment = Ext.getCmp('tingcomment');
										TingComment.refresh();
										Ext.getCmp('tingcommentText').reset();
										Ext.Msg.alert('', '댓글이 등록되었습니다.', Ext.emptyFn);
	            					}
	            				});
	 						}
	 					});
 					
 				}
    		}]
   		}]
	}
});

Ext.define('TingCommentItem', {
	extend: 'Ext.dataview.component.DataItem',
    xtype: 'TingCommentItem',
	config: {
		listeners: {
			initialize: function() {
					var writerid = this.getRecord().get('WriterID');
					
					var img = this.getItems().items[1];
					img.setSrc('https://graph.facebook.com/'+writerid+'/picture');
					
					var userid = UserStore.getAt(0).data.ID;
					var delbtn = this.getItems().items[2];
					if (userid == writerid) {
						delbtn.show();
					} else {
						Ext.emptyFn
					}
			}
		},
		layout: 'hbox',
		style: 'background:white;border-bottom:1px #CBCAC7 solid;margin-left:-17px',
		width: '105%',
		items: [
		{
			xtype: 'panel',
			style: 'word-break:break-all; padding-right:35px; background:white;',
			tpl: '<a class="writer">{Writer}</a><br>{Text}<br><font size="2">{Date}&nbsp;&nbsp;&nbsp;&nbsp;{Time}</font>',
			listeners: {
				tap: {
					element: 'element',
					delegate: 'a.writer',
					fn: function() {
						var dataitem = this.getParent();
						var otherid = dataitem.getRecord().get('WriterID');
						openOtherinfo(otherid)
					}
				}
			}
		},
		{
			xtype: 'img',
			height: 64,
			width: 64,
			style: 'margin-top:15px',
			docked: 'left',
			listeners: {
				tap: function() {
						var dataitem = this.getParent();
						var otherid = dataitem.getRecord().get('WriterID');
						openOtherinfo(otherid)
					}
			}
		},
		{
				xtype: 'button',
				text: 'X',
				style: 'background:white;border:0px solid',
				docked: 'right',
				width: 32,
				height: 32,
				hidden: true,
				handler: function() {
					var dataitem = this.getParent();
					var commentnum = dataitem.getRecord().get('Number');
					var tingnum = dataitem.getRecord().get('TingNumber');
					
					
					Ext.Msg.show({
	  					message: '삭제하시겠습니까?',
	   		        	width: 300,
	   					buttons:  [{
	   						id: 'ok',
	   						text: 'Ok',
	   						ui: 'action'
	   					},
	   					{	
	   						id: 'cancel',
	   						text: 'Cancel'
	   					}],   					
	   					fn: function(buttonId) {
	       					if (buttonId == 'Ok') {
	       						Ext.data.JsonP.request({
	 								url: 'http://itscreater.cafe24.com/Triends/TingCommentDelete.jsp',
	 								params: {num: commentnum},
	 								callbackkey: 'callback',
	 								success: function() {
	 									var TingCommentStore = Ext.getStore('TingCommentStore'+tingnum);
										TingCommentStore.remove(dataitem.getRecord());
										var TingComment = Ext.getCmp('tingcomment');
										TingComment.refresh();
	 								}
	 							});
							} else if (buttonId == 'Cancel') {
	       						Ext.emptyFn
	       					}
	   					}
					});
			}
		}]
    }
});

function openTinginfo(model, tingnum) {
	var activetab = Ext.getCmp('main').getActiveItem().id;

	var tinginfoStore = Ext.getStore('tinginfoStore'+tingnum);
	if (Ext.typeOf(tinginfoStore) == 'object') {
		tinginfoStore.removeAll();
		tinginfoStore.setData(model.data);
	} else {
		tinginfoStore = Ext.create("Ext.data.Store",{
			model: 'Triends.Tinginfo'});
		tinginfoStore.setStoreId('tinginfoStore'+tingnum);
		tinginfoStore.setData(model.data);
	}
	
	var AttendeeStore = Ext.getStore('AttendeeStore'+tingnum);
	if (Ext.typeOf(AttendeeStore) == 'object') {
		AttendeeStore.removeAll();
	} else {
		AttendeeStore = Ext.create("Ext.data.Store",{
			model: 'Triends.Model.AttendeeList'});
		AttendeeStore.setStoreId('AttendeeStore'+tingnum);
	}
	
	var TingCommentStore = Ext.getStore('TingCommentStore'+tingnum);
	if (Ext.typeOf(TingCommentStore) == 'object') {
		TingCommentStore.removeAll();
	} else {
		TingCommentStore = Ext.create("Ext.data.Store",{
			model: "Triends.Model.TingComment",
			sorters: [
		{
			property: 'Date',
			direction: 'ASC'
		},
		{
			property: 'Time',
			direction: 'ASC'
		}
	]});
		TingCommentStore.setStoreId('TingCommentStore'+tingnum);	
	}
			 		
	Ext.data.JsonP.request({
    	url: 'http://itscreater.cafe24.com/Triends/AttendeeList.jsp',
        params: {num: tingnum},
        callbackKey: 'callback',
        success: function(result) {
			AttendeeStore.setData(result);
		
			Ext.data.JsonP.request({
    			url: 'http://itscreater.cafe24.com/Triends/TingCommentList.jsp',
    			params: {num: tingnum},
    			callbackKey: 'callback',
        		success: function(result) {
					TingCommentStore.setData(result);
					Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
    				url: 'tinginfo/' + activetab + '/' + tingnum
    			}));
        	}
    	});
        }
    });
}

function otherinfo() {
	var otherid = Ext.getCmp("hostpanel").getData().ID;
	var cacaocheck;
	if (Ext.getCmp('tingjoinbtn').isHidden() == false) {
  		cacaocheck = 'cannot';
 	} else {
 		cacaocheck = 'can'
	}
	openOtherinfo(otherid, cacaocheck)
}

Ext.define("Triends.Tinginfo",{
	extend: "Ext.data.Model",
	config: {
		fields: ["NUMBER", "ID", "HOST", "TITLE", "THEME", "LAT", "LNG", "CONTENT", "STARTDATE", "STARTTIME"]
	}
});

Ext.define('Triends.view.Tinginfo', {
 	extend: 'Ext.Panel',
 	requires: ['Triends.view.MapOverlay2','Triends.view.AttendeeList', 'Triends.view.TingComment', 'Triends.view.Othersinfo', 'Triends.view.TingModify'],
 	xtype: 'tinginfo',
 	id: 'tinginfo',
 	alias: 'tingpage',
 	config: {
 		fullscreen: true,
 		showAnimation: 'slideIn',
 		scrollable: true,
 		layout: 'vbox',
 		listeners: {
 			deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					Ext.getCmp('tinginfo').destroy();
				}
 		},
 		items: [{
 			xtype: 'panel',
 			layout: 'hbox',
 			minHeight: 90,
 			style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))', 'padding':'15px'},
			items:[
				{	
					xtype: 'panel',
					width: 60,
					items: [{
						xtype: 'image',
						id: 'tinginfotheme',
						width: 48,
						height: 48,
						centered: true
					}]
				},
				{
					xtype: 'panel',
					maxWidth: '80%',
					id: 'tingtitlepanel',
					style: {'word-break':'break-all', 'margin-left':'10px', 'padding-right':'15px'},
					tpl: [
						"<p style='margin-left:10px'><font size='5'><b>{TITLE}</b></font></p>"
					]
				}
			]
		},
		{
			xtype: 'panel',
			layout: 'vbox',
			style: {'padding':'15px'},
			items: [
				{
					xtype: 'panel',
					style: 'margin-bottom:10px',
					html: "<p style='margin-left:5px'><font size='4'><b>Location & Time</b></font></p>"
				},
				{
					xtype: 'panel',
					layout: 'hbox',
					items: [{
						xtype: 'panel',
						items:[{
							xtype: 'button',
							iconCls: 'locate',
							iconMask: true,
							style: 'margin-left:5px; background: -webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))',
							height: 48,
							width: 48,
							handler: function(btn) {
								var tingnum = Ext.getCmp("hostpanel").getData().NUMBER;
				 				var lat2 = Ext.getStore('tinginfoStore'+tingnum).getAt(0).data.LAT;
				 				var lng2 = Ext.getStore('tinginfoStore'+tingnum).getAt(0).data.LNG;
				 				
				 				var latlng = new google.maps.LatLng(lat2, lng2);
				 				var map3 = Ext.create("Ext.Map",{
									id: "map3",
									width:300,
									mapOptions: {
										center: latlng,
										zoom: 14,
										zoomControl: true,
										mapTypeId: google.maps.MapTypeId.ROADMAP,
										mapTypeControl: false,
										streetViewControl: false
									},
									listeners: {
										maprender: function(comp, map){
											var marker = new google.maps.Marker({
												map: map,
												position: latlng,
												icon: 'resource/images/mappin1.png'
											});
										}
									}
								});
				
				 				var mapOverlay2 = Ext.create("Triends.view.MapOverlay2");
				 				mapOverlay2.add(map3);
				 				Ext.Viewport.add(mapOverlay2);
	 						}
						}]	
					},
					{	
							xtype: 'panel',
							id: 'tingtimepanel',
							tpl: [
								"<p style='margin-left:30px;margin-bottom:5px'><font size='3'>{STARTDATE}</font></p>"+
								"<p align='right'><font size='3'>{STARTTIME}</font></p>"
							]
					}]
				},
				{
					xtype: 'panel',
					id: 'tinghostpanel',
					style: 'margin-top:20px;',
					layout: 'vbox',
					items:[{
							xtype: 'panel',
							html: "<p style='margin-left:5px'><font size='4'><b>Host</b></font></p>"

						},
						{
							xtype: 'panel',
							layout: 'hbox',
							style: 'margin-top:20px',
							items: [
								{
									xtype: 'panel',
									layout: 'hbox',
									style: 'border-top:1px #CBCAC7 solid;background: #fff',
									width: '100%',
									height: 70,
									items: [
										{
											xtype: 'panel',
											width: 60,
											items:[{
													xtype: 'image',
													id: 'hostimg',
													width: 48,
													height: 48,
													centered: true,
													listeners: {
														tap:function(){
															otherinfo();
														}		
													}
											}]
										},
										{
											xtype: 'panel',
											id: 'hostpanel',
											style: 'padding-top:10px;',
											maxWidth: '80%',
											tpl: "<a href='#'><span style='margin-left:20px;'><font size='4' color='#2E2EFE'><u>{HOST}</u></font></span></a>",		
											listeners: {
												tap: {
													element: 'element',
													fn: function() {
														otherinfo();
													}
												}
											}
										}	
									]
								},
								{
									xtype: 'panel',
									layout: 'vbox',
									height: 100,
									docked: 'right',
									items: [
										{					
											xtype: 'panel',
											style: 'margin-bottom:5px',
											items: [{
												xtype: 'button',
												iconCls: 'trash',
												style: 'background: -webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))',
												iconMask: true,
												hidden: true,
												width: '48px',
												height: '32px',
												id: 'tingdeletebtn',
												handler: function() {
										          	Ext.Msg.show({
									  					title: '알림',
									  					message: 'Ting을 삭제하시겠습니까?',
									   		            width: 300,
									   					buttons:  [{
									   						text: 'Ok',
									   						id: 'ok',
									   						ui: 'action'
									   					},
									   					{	
									   						text: 'Cancel',
									   						id: 'cancel'
									   					}],   					
									   					fn: function(buttonId) {
									       					if (buttonId == 'Ok') {
									       						var userid = Ext.getStore('UserStore').getAt(0).data.ID;
									       						
									       						var thisview = Ext.getCmp('hostpanel');
											    				var num = thisview.getData().NUMBER;
									
									    	  					Ext.data.JsonP.request({
									   								url: 'http://itscreater.cafe24.com/Triends/TingDelete.jsp',
									   								params: {
									   									num : num
									   								},
									          						callbackKey: 'callback',
									          						success: function(result) {
									          							
									          							var tingStore = Ext.getStore('tingstore');
									         							tingStore.load({
									         								callback: function() {
									         									
											         							var userHOSTtingStore = Ext.getStore('userHOSTtingstore');
																					userHOSTtingStore.getProxy().setExtraParams({id: userid});
																					userHOSTtingStore.load({
																						callback: function() {
																							Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
						            															url: 'mainpage'
						        															}));
																						}
																					});
									         								}
									         							});
																	}
									    		  				});	
									       					} else if (buttonId == 'Cancel') {
									       						Ext.emptyFn;
									       					}
									   					}
													});
												}
											}]
										},
										{
													xtype: 'panel',
													items:[{					
														xtype: 'button',
														iconCls: 'settings',
														iconMask: true,
														width: '48px',
														style: 'background: -webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))',
														height: '32px',
														hidden: true,
														id: 'tingmodifybtn',
														handler: function(){
															var activetab = Ext.getCmp('main').getActiveItem().id;
															Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
								            					url: 'tingmodify/'+ activetab
								        					}));
														}
													}]
											}]
								}]
						},
						{
										xtype: 'panel',
										layout: 'vbox',
										style: 'margin-top:-15px',
										docked: 'bottom',
										items:[{
												xtype: 'button',
									 			text: 'Join',
									 			id: 'tingjoinbtn',
									 			style: 'background: -webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))',
									 			iconCls: 'arrow_right',
									 			iconMask: true,
									 			ui: 'small',
									 			hidden: true,
									 			docked: 'right',
									 			width: 130,
									 			handler: function() {
									 				Ext.Msg.show({
									  					title: '알림',
									  					message: 'Ting에 참가하시겠습니까?',
									   		            width: 300,
									   					buttons:  [{
									   						id: 'ok',
									   						text: 'Ok',
									   						ui: 'action'
									   					},
									   					{	id: 'cancel',
									   						text: 'Cancel'
									   					}],   					
									   					fn: function(buttonId) {
									       					if (buttonId == 'Ok') {
									       						
									       						var userid = Ext.getStore('UserStore').getAt(0).data.ID;
									       						var username = Ext.getStore('UserStore').getAt(0).data.Name;
									       						
									       						// 현재 팅 페이지의 번호를 받음
									 							var thisview = Ext.getCmp('tingtitlepanel');
											    				var tingnum = thisview.getData().NUMBER;
											    				var hostid = thisview.getData().ID;
											    				var hostname = thisview.getData().HOST;
											    				
														    	Ext.data.JsonP.request({
									   								url: 'http://itscreater.cafe24.com/Triends/TingJoin.jsp',
									   								params: {
									   									userid: userid,
									   									username: username,
									   									num : tingnum,
									   									hostid: hostid,
									   									hostname: hostname
									   								},
									          						callbackKey: 'callback',
									          						success: function(result) {
												          				if (result.success == 'true') {
												          					var userdata = Ext.getStore('UserStore').getAt(0)
												          					var AttendeeStore = Ext.getStore('AttendeeStore'+tingnum);
												          					AttendeeStore.add(userdata);
									          								var attendeelistpanel = Ext.getCmp('attendeelistpanel');
									          								attendeelistpanel.refresh();
									          								
									         								var tingjoinbtn = Ext.getCmp("tingjoinbtn");
									        									tingjoinbtn.setHidden(true);
									        								var tingjcancelbtn = Ext.getCmp("tingjoincancelbtn");
												        						tingjcancelbtn.setHidden(false);
												        					var userATTENDtingStore = Ext.getStore('userATTENDtingstore');		
																				userATTENDtingStore.getProxy().setExtraParams({id: userid});
																				userATTENDtingStore.load();
												        						
												          				} else if (result.success == 'false') {
												          					Ext.Msg.alert('알림', '이미 참여한 Ting입니다', Ext.emptyFn);
												          				}
									         						}
									    		  				});	
									       					} else if (buttonId == 'Cancel') {
									       						Ext.emptyFn;
									       					}
									   					}
													});
												}
										},
										{
										
												xtype: 'button',
									 			text: 'Join Cancel',
									 			id: 'tingjoincancelbtn',
									 			iconCls: 'arrow_left',
									 			style: 'background: -webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))',
									 			iconMask: true,
									 			ui: 'small',
									 			docked: 'right',
									 			hidden: true,												 			
									 			width: 130,
									 			handler: function() {
									 				Ext.Msg.show({
									  					title: '알림',
									  					message: 'Ting참가를 취소하시겠습니까?',
									   		            width: 300,
									   					buttons:  [{
									   						id: 'ok',
									   						text: 'Ok',
									   						ui: 'action'
									   					},
									   					{	id: 'cancel',
									   						text: 'Cancel'
									   					}],   					
									   					fn: function(buttonId) {
									       					if (buttonId == 'Ok') {
									       						
									       						var userid = Ext.getStore('UserStore').getAt(0).data.ID;
									       						var username = Ext.getStore('UserStore').getAt(0).data.Name;
									       						// 현재 팅 페이지의 번호를 받음
									 							var thisview = Ext.getCmp('tingtitlepanel');
											    				var tingnum = thisview.getData().NUMBER;
											    				var hostid = thisview.getData().ID;
											    				var hostname = thisview.getData().HOST;
											    	
														    	Ext.data.JsonP.request({
									   								url: 'http://itscreater.cafe24.com/Triends/TingJoinCancel.jsp',
									   								params: {
									   									userid: userid,
									   									username: username,
									   									num : tingnum,
									   									hostid: hostid,
									   									hostname: hostname
									   								},
									          						callbackKey: 'callback',
									          						success: function(result) {
									          							
												          				var AttendeeStore = Ext.getStore('AttendeeStore'+tingnum);
												          				
												          				var userdata = AttendeeStore.findRecord('ID', userid);
												          				AttendeeStore.remove(userdata);
									          							var attendeelistpanel = Ext.getCmp('attendeelistpanel');
									          							attendeelistpanel.refresh();
									          							
									         							var userATTENDtingStore = Ext.getStore('userATTENDtingstore');		
																			userATTENDtingStore.getProxy().setExtraParams({id: userid});
																			userATTENDtingStore.load();
												          				
												          				var tingjoinbtn = Ext.getCmp("tingjoinbtn");
									        							var tingjcancelbtn = Ext.getCmp("tingjoincancelbtn");
									        							tingjoinbtn.setHidden(false);
									        							tingjcancelbtn.setHidden(true);
									         						}
									    		  				});	
									       						
									       					} else if (buttonId == 'Cancel') {
									       						Ext.emptyFn;
									       					}
									   					}
													});
												}
											}]
									
								}
					]
			}]
		},
		{},
		{
			xtype: 'panel',
			layout: 'vbox',
			width: '100%',
			style: 'padding:15px; border-top:1px #CBCAC7 solid',
			items: [
 				{
 	 				xtype: 'panel',
 	 				layout: 'hbox',
 	 				width: '100%',
 	 				items: [
 	 				{
	 	 					xtype: 'panel',
		 	 				html: "<p style='margin-left:5px;'><font size='4'><b>Description</b></font></p>"
	 	 			},
	 	 			{
						xtype: 'button',
						id: 'expandbutton',
						style: 'background: transparent; border-color: transparent; margin-top:-5px',
						height: 20,
						docked: 'right',
						iconCls: 'arrow_down',
						iconMask: true,
						handler: function(){
							var expandbutton = Ext.getCmp('expandbutton'); 
							var collapsebutton = Ext.getCmp('collapsebutton');
							var tingcontentpanel = Ext.getCmp('tingcontentpanel');
							expandbutton.setHidden(true);
							collapsebutton.setHidden(false);
							tingcontentpanel.setMaxHeight(500);
						}
					},
					{
						xtype: 'button',
						id: 'collapsebutton',
						style: 'background: transparent; border-color: transparent; margin-top:-5px',
						height: 20,
						hidden: true,
						docked: 'right',
						iconCls: 'arrow_up',
						iconMask: true,
						text: '',
						handler: function(){
							var expandbutton = Ext.getCmp('expandbutton');
							var collapsebutton = Ext.getCmp('collapsebutton');
							var tingcontentpanel = Ext.getCmp('tingcontentpanel');
							collapsebutton.setHidden(true);
							expandbutton.setHidden(false);
							tingcontentpanel.setMaxHeight(50);
						}
					}]
 	 			},
 	 			{
 	 				xtype: 'panel',
 	 				id: 'tingcontentpanel',
 	 				width: '100%',
 	 				maxHeight: 50,
 	 				cls: 'contentellipsis',
					tpl: ["<font size='3'>&nbsp;&nbsp;{CONTENT}</font>"]
 	 			}]
		},
		{
			xtype: 'attendeelist'
		},
 	 	{
 	 		xtype: 'panel',
 	 		style: 'padding-top:15px; padding-left:15px;border-top:1px #CBCAC7 solid',
 	 		items:[
 	 			{
 	 				xtype: 'panel',
 	 				style: 'margin-bottom:-10px',
 	 				html: "<p style='margin-left:5px;'><font size='4'><b>Comment</b></font></p>"
 	 			},
 	 			{
 	 				xtype: 'tingcomment'
 	 		}]
 	 	}]
 	}
 });
	 
 Ext.define('Triends.view.TingModify', {
 	extend: 'Ext.form.Panel',
 	requires: 'Triends.view.MapOverlay3',
 	xtype: 'tingmodify',
 	id: 'tingmodify',
 	config: {
 		fullscreen: true,
 		showAnimation: 'slideIn',
 		listeners: {
 			deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					oldActiveItem.destroy();
				}
 		},
 		items: [
 			{
	 			xtype: 'fieldset',
	 			title: 'Title',
	 			items: [
	 				{
	 					xtype: 'textfield',
	 					id: 'tingmdftitle',
	 					style: 'border:3px inset',
 						maxLength: 50,
 						placeHolder: '50자 이내로 작성하세요',
 						listeners: {
 							keyup: function() {
 								var length = this.getValue().length;
 								Ext.getCmp('tingmdftitlecount').setHtml(length+'/50');
 							},
 							clearicontap: function() {
 								Ext.getCmp('tingmdftitlecount').setHtml('0/50');
 							}
 						}
 					}]
 			},
 			{
					xtype: 'panel',
					items: [{
						xtype: 'panel',
						docked: 'right',
						width: 50,
						style: 'background: #eee;margin-top:-20px;',
 						id: 'tingmdftitlecount'
					}]
 			},
 			{	
 				xtype: 'panel',
 				layout: 'hbox',
 				width: "100%",
 				items: [{
	 				xtype: 'fieldset',
	 				layout: 'hbox',
	 				title: 'Theme',
	 				width: '92%',
	 				items: [
	 					{
			 				 xtype: 'selectfield',
			 				 style: 'border:3px inset',
			 				 flex: 9,
			 				 usePicker: false,
			 				 id: 'tingmdftheme',
			 				 options: [
			 				 	{text: ' ', value: ' '},
			 				 	{text: '술', value: 'drink'},
			 				 	{text: '식사', value: 'meal'},
			 				 	{text: '여행동행', value: 'accompany'},
			 				 	{text: '공연관람', value: 'view'},
			 				 	{text: '클러빙', value: 'club'},
			 				 	{text: '야경', value: 'nightview'},
			 				 	{text: '숙소 공유', value: 'accomodation'},
			 				 	{text: '교통 동행', value: 'transportation'},
			 				 	{text: '기타', value: 'etc'}
			 				 ],
			 				 listeners:{
			 				 	change: function(selectbox,newValue,oldValue){
			 				 		var tingmdfthemevalue = Ext.getCmp('tingmdftheme').getValue();
			 				 		Ext.getCmp('mdfthemeimage').setSrc('resource/images/'+tingmdfthemevalue+'.png');	
			 				 	}
			 				 }
						}
					]
 				},
 				{
					xtype: 'spacer',
					width: '2%'
				},
				{
					xtype: 'panel',
					docked: 'right',
					width: 48,
					height: 48,
					style: 'margin-top:45px',
					items: [{
						xtype: 'image',
						id: 'mdfthemeimage',
						width: 48,
						height: 48
					}]
				}]
 			},
 			{ 			
	 			xtype: 'panel',
	 			layout: 'vbox',
	 			items: [
	 			{
	 				xtype: 'fieldset',
	 				title: 'Date',
	 				items:[
				 			{
								xtype: 'datepickerfield',
								label: 'Date',
								style: 'border:3px inset',
								id: 'tingmdfdate',
								dateFormat: "Y/m/d",
								picker: {
										yearFrom: 2012,
										yearTo: 2015,
										slotOrder: ['year', 'month', 'day'],
										useTitles: true}
			 				},
			 				{
			 					xtype: 'selectfield',
			 					label: 'AM/PM',
			 					style: 'border:3px inset',
			 					id: 'tingmdfampm',
			 					options: [
			 						{text: "", value: ""},
			 						{text: 'AM', value: 'AM'},
			 						{text: 'PM', value: 'PM'}
			 					]
			 				},
			 				{
			 					xtype: 'selectfield',
			 					label: 'Hour',
			 					style: 'border:3px inset',
			 					id: 'tingmdfhour',
			 					options: [
			 						{text: "", value: ""},
			 						{text: '00', value: 00},
			 						{text: '01', value: 01},
			 						{text: '02', value: 02},
			 						{text: '03', value: 03},
			 						{text: '04', value: 04},
			 						{text: '05', value: 05},
			 						{text: '06', value: 06},
			 						{text: '07', value: 07},
			 						{text: '08', value: 08},
			 						{text: '09', value: 09},
			 						{text: '10', value: 10},
			 						{text: '11', value: 11},
			 						{text: '12', value: 12}
			 					]
			 				},
			 				{
			 					xtype: 'selectfield',
			 					label: 'Minute',
			 					style: 'border:3px inset',
			 					id: 'tingmdfminute',
			 					options:[
			 						{text: "", value: ""},
			 						{text: '00', value: '00'},
			 						{text: '30', value: '30'}
			 					]
			 				}	
	 				]
	 			},
 				{
 					xtype: 'spacer'
 				},
 				{
 					xtype: 'panel',
 					style: 'margin-top:15px',
 					layout: 'vbox',
 					items:[
 						{
 							xtype: 'panel',
							style: 'margin-left:15px;margin-bottom:5px',
 							html: '<b>Location</b>'
 						},
 						{
 							xtype: 'button',
		 					iconCls: 'locate',
		 					iconMask: true,
		 					style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 					width: '100%',
		 					handler: function(btn){
		 						var mapOverlay3 = Ext.create("Triends.view.MapOverlay3")
		 						
								var lat2 = Ext.getCmp("tingmodify").getData().LAT;
					 			var lng2 = Ext.getCmp("tingmodify").getData().LNG;
								
					 			var latlng = new google.maps.LatLng(lat2, lng2);
								var map4 = Ext.create("Ext.Map",{
									id: 'map4',
									width:300,
									mapOptions: {
										center: latlng,
										zoom: 14,
										zoomControl: true,
										mapTypeId: google.maps.MapTypeId.ROADMAP,
										streetViewControl: false,
										mapTypeControl: false,
										disableDoubleClickZoom: true
									},
									listeners: {
										maprender: function(comp, map){
											var latlng = new google.maps.LatLng(lat2, lng2);
											var selectedLocation;
											
											var marker = new google.maps.Marker({
												map: map,
												position: latlng,
												icon: 'resource/images/mappin1.png'
											});
											google.maps.event.addListener(map, 'dblclick', function(event){ // map은 항상 map, click이 아니라 mousedown 이벤트다!
												selectedLocation = event.latLng;
												marker.setPosition(selectedLocation);
												lat = selectedLocation.lat();
												lng = selectedLocation.lng();
											});	
										}
									}
								})
		 						mapOverlay3.add(map4);  
		 						Ext.Viewport.add(mapOverlay3);	
 						}
 					}]
 				}]	
 			},
	 		{
	 			xtype: 'fieldset',
	 			title: 'Discription',
	 			style: 'margin-top:30px',
	 			items: [{
	 				xtype: 'textareafield',
	 				id: 'tingmdfcontent',
	 				maxRows: 7,
	 				style: 'border:3px inset',
	 				placeHolder: '250자 이내로 작성하세요',
	 				height: 200,
	 				listeners: {
 						keyup: function() {
 							var length = this.getValue().length;
 							Ext.getCmp('tingmdfcontentcount').setHtml(length+'/250');
 						},
 						clearicontap: function() {
	 						Ext.getCmp('tingmdfcontentcount').setHtml('0/250');
 						}
 					}
	 			}]
	 		},
	 		{
 					xtype: 'panel',
					items: [{
						xtype: 'panel',
						docked: 'right',
						width: 60,
						style: 'background: #eee;margin-top:-20px;',
	 					id: 'tingmdfcontentcount'
					}]
 			},
 			{
 				xtype: 'panel',
 				layout: 'hbox',
 				items: [{
 					xtype: 'button',
 					width: '100%',
 					style: {'margin-top':'20px','left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 			text: 'Modify',
		 			handler: function(){
		 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
		 				var tingnum = Ext.getCmp("tingmodify").getData().NUMBER;
						var tingmdftitle = Ext.getCmp("tingmdftitle").getValue();
						var tingmdftheme = Ext.getCmp("tingmdftheme").getValue();
						var tingmdfdate = Ext.getCmp("tingmdfdate").getFormattedValue();
						var tingmdfampm = Ext.getCmp("tingmdfampm").getValue();
 						var tingmdfhour = Ext.getCmp("tingmdfhour").getValue();
 						var tingmdfminute = Ext.getCmp("tingmdfminute").getValue();
 						if (tingmdfampm == 'PM'){
 							tingmdfhour += 12;
 						};
 						var tingmdftime = tingmdfhour+":"+tingmdfminute;
 						var tingmdfcontent = Ext.getCmp("tingmdfcontent").getValue();
 						
 						Ext.Ajax.request({
							url: 'http://itscreater.cafe24.com/Triends/TingModify.jsp',
							params: {num: tingnum, tingtitle: tingmdftitle, tingcontent: tingmdfcontent, tingtheme:tingmdftheme, 
									tingdate: tingmdfdate, tingtime: tingmdftime},
//							callbackkey: 'callback',
							success: function(response){
//								var result = Ext.JSON.decode(response.responseText);
//            					console.log(result.error);
								
								var userHOSTtingStore = Ext.getStore('userHOSTtingstore');
									userHOSTtingStore.getProxy().setExtraParams({id: userid});
									userHOSTtingStore.load({
										callback: function() {
											tingStore.loadPage(1);		
											Ext.Msg.show({
												title: "",
												message: 'Ting이 수정되었습니다',
												buttons: [{text: '확인', itemId:'ok', ui: 'action'}],
												fn: function(buttonId){
													Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            											url: 'mainpage'
        											}));
        										}
											});
										}
									});
							}
						})
 						
		 			}
 				}]
 			}]
 		}
});

Ext.define('Triends.view.TingOpen', {
 	extend: 'Ext.form.Panel',
 	requires: ['Triends.view.MapOverlay'], 
 	xtype: 'tingopen',
 	id: 'tingopen',
 	config: {
 		fullscreen: true,
 		layout: 'vbox',
 		showAnimation: 'slideIn',
 		listeners: {
 			activate: function(oldActiveItem, container, newActiveItem, eOpts) {
					var tingopenbtn = Ext.getCmp('tingopenbtn');
					tingopenbtn.hide();
					var titlebar = Ext.getCmp('titlebar');
					titlebar.hide();
				},
			deactivate: function(oldActiveItem, container, newActiveItem, eOpts) {
					var tingopenbtn = Ext.getCmp('tingopenbtn');
					tingopenbtn.show();
					var titlebar = Ext.getCmp('titlebar');
					titlebar.show();
					Ext.getCmp("tingtitle").reset();
					Ext.getCmp("tingcontent").reset();
					Ext.getCmp("tingtheme").reset();
					Ext.getCmp("tingdate").reset();
					Ext.getCmp("tingampm").reset();
					Ext.getCmp("tinghour").reset();
					Ext.getCmp("tingminute").reset();
				}
			
 		},
 		items: [
 			{
 				xtype: 'panel',
 				html: "<div align='center'><font size='5'><b>Ting Open</b></font></div>"
 			},
 			{
	 			xtype: 'fieldset',
	 			title: 'Title',
	 			items: [{
	 					xtype: 'textfield',
	 					id: 'tingtitle',
	 					style: 'border:3px inset'
	 				}
	 			]
 			},
 			{
 				xtype: 'panel',
 				layout: 'hbox',
 				width: "100%",
 				items: [{
	 				xtype: 'fieldset',
	 				title: 'Theme',
	 				layout: 'hbox',
					width: '92%',
	 				items: [
	 					{
			 				 xtype: 'selectfield',
			 				 style: 'border:3px inset',
			 				 flex: 9,
			 				 usePicker: false,
			 				 id: 'tingtheme',
			 				 options: [
			 				 	{text: ' ', value: ' '},
			 				 	{text: '술', value: 'drink'},
			 				 	{text: '식사', value: 'meal'},
			 				 	{text: '여행 동행', value: 'accompany'},
			 				 	{text: '공연 관람', value: 'view'},
			 				 	{text: '클러빙', value: 'club'},
			 				 	{text: '야경', value: 'nightview'},
			 				 	{text: '숙소 공유', value: 'accomodation'},
			 				 	{text: '교통 동행', value: 'transportation'},
			 				 	{text: '기타', value: 'etc'}
			 				 ],
			 				 listeners:{
			 				 	change: function(selectbox,newValue,oldValue){
			 				 		var themevalue = Ext.getCmp('tingtheme').getValue();
			 				 		Ext.getCmp('themeimage').setHidden(false);
			 				 		Ext.getCmp('themeimage').setSrc('resource/images/'+themevalue+'.png');	
			 				 	}
			 				 }
					}] 
 				},
 				{
					xtype: 'spacer',
					width: '2%'
				},
				{
					xtype: 'panel',
					docked: 'right',
					width: 48,
					height: 48,
					style: 'margin-top:45px',
					items: [{
						xtype: 'image',
						id: 'themeimage',
						width: 48,
						height: 48
					}]
				}]
 			},
 			{ 			
	 			xtype: 'panel',
	 			layout: 'vbox',
	 			items: [
	 			{
	 				xtype: 'fieldset',
	 				title: 'Time',
	 				items:[
				 			{
								xtype: 'datepickerfield',
								label: 'Date',
								style: 'border:3px inset',
								id: 'tingdate',
								dateFormat: "Y-m-d",
								picker: {
										hideOnMaskTap: true,
										yearFrom: 2012,
										yearTo: 2015,
										slotOrder: ['year', 'month', 'day'],
										useTitles: true
								}
			 				},
			 				{
			 					xtype: 'selectfield',
			 					label: 'AM/PM',
			 					style: 'border:3px inset',
			 					usePicker: false,
			 					id: 'tingampm',
			 					options: [
			 						{text: "", value: ""},
			 						{text: 'AM', value: 'AM'},
			 						{text: 'PM', value: 'PM'}
			 					]
			 				},
			 				{
			 					xtype: 'selectfield',
			 					label: 'Hour',
			 					style: 'border:3px inset',
			 					usePicker: false,
			 					id: 'tinghour',
			 					options: [
			 						{text: "", value: ""},
			 						{text: '00', value: 00},
			 						{text: '01', value: 01},
			 						{text: '02', value: 02},
			 						{text: '03', value: 03},
			 						{text: '04', value: 04},
			 						{text: '05', value: 05},
			 						{text: '06', value: 06},
			 						{text: '07', value: 07},
			 						{text: '08', value: 08},
			 						{text: '09', value: 09},
			 						{text: '10', value: 10},
			 						{text: '11', value: 11},
			 						{text: '12', value: 12}
			 					]
			 				},
			 				{
			 					xtype: 'selectfield',
			 					label: 'Minute',
			 					style: 'border:3px inset',
			 					usePicker: false,
			 					id: 'tingminute',
			 					options:[
			 						{text: "", value: ""},
			 						{text: '00', value: '00'},
			 						{text: '30', value: '30'}
			 					]
			 				}	
	 				]
	 			},
	 			
 				{
 					xtype: 'spacer'
 				},
 				{	
 					xtype: 'panel',
 					style: 'margin-top:15px',
 					layout: 'vbox',
 					items:[
 						{
 							xtype: 'panel',
							style: 'margin-left:15px;margin-bottom:5px',
 							html: '<b>Location</b>'
 						},
 						{
		 					xtype: 'button',
		 					iconCls: 'locate',
		 					style: {'left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 					width: '100%',
		 					iconMask: true,
		 					handler: function(){
								var mapOverlay = Ext.create("Triends.view.MapOverlay");						
		 						var map2 = Ext.create("Triends.Map2");
		 						mapOverlay.add(map2); // 그냥 items에 집어 넣었더니 안뜬다.
								Ext.Viewport.add(mapOverlay); 							
	 					}
 					}]
 				}
 				]	
 			},
	 		{
	 			xtype: 'fieldset',
	 			title: 'Description',	 
	 			style: 'margin-top:30px',
	 			items: [{
	 				xtype: 'textareafield',
	 				id: 'tingcontent',
	 				maxRows: 7,
	 				style: 'border:3px inset',
	 				height: 200
	 			}]
	 		},
 			{
 				xtype: 'panel',
 				layout: 'hbox',
 				items: [{
 					xtype: 'button',
		 			text: 'Open',
		 			style: {'margin-top':'20px','left':'50%', 'margin-left':'-50%', 'border': '1px outset'},
		 			width: '100%',
		 			handler: function(){
		 				try{
			 				var userid = Ext.getStore('UserStore').getAt(0).data.ID;
			 				var username = Ext.getStore('UserStore').getAt(0).data.Name;
			 				
			 				var tingtitle = Ext.getCmp("tingtitle").getValue();
			 				var tingcontent = Ext.getCmp("tingcontent").getValue();
			 				var tingtheme = Ext.getCmp("tingtheme").getValue();
			 				var tingdate = Ext.getCmp("tingdate").getFormattedValue();
			 				var tingampm = Ext.getCmp("tingampm").getValue();
	 						var tinghour = Ext.getCmp("tinghour").getValue();
	 						var tingminute = Ext.getCmp("tingminute").getValue();
	 						if (tingampm == 'PM'){
	 							tinghour += 12;
	 						};
	 						var tingtime = tinghour+":"+tingminute;
			 				var ting = Ext.getCmp("ting");
							var tingStore = Ext.getStore("tingstore");
							
							if(tingtitle == ""){
								Ext.Msg.alert("","Title을 입력하세요");
								return;
							}
							if(tingtheme == ""){
								Ext.Msg.alert("","Theme을 입력하세요");
								return;
							}
							if(tingdate == ""){
								Ext.Msg.alert("","Date를 선택하세요");
								return;
							}
							if(tingampm == ""){
								Ext.Msg.alert("","AM/PM을 선택하세요");
								return;
							}
							if(tinghour == ""){
								Ext.Msg.alert("","Hour를 선택하세요");
								return;
							}
							if(tingminute == ""){
								Ext.Msg.alert("","Minute을 선택하세요");
								return;
							}
							if(localStorage.lat == null){
								Ext.Msg.alert("","위치를 선택하세요");
								return;
							}
							if(tingcontent == ""){
								Ext.Msg.alert("","Content를 입력하세요");
								return;
							}
							
							
			 				Ext.Ajax.request({
								url: 'http://itscreater.cafe24.com/Triends/TingOpen.jsp',
								params: {id: userid, name: username, tingtitle: tingtitle, tingcontent: tingcontent, tingtheme:tingtheme, 
										lat: localStorage.lat, lng: localStorage.lng, 
										tingdate: tingdate, tingtime: tingtime},
//								callbackkey: 'callback',
								success: function(response){
									
									var result = Ext.JSON.decode(response.responseText);
            					console.log(result.error);
									var userHOSTtingStore = Ext.getStore('userHOSTtingstore');
										userHOSTtingStore.getProxy().setExtraParams({id: userid});
										userHOSTtingStore.load();
									
									tingStore.loadPage(1);		
									Ext.Msg.show({
										title: "",
										message: 'Ting이 등록되었습니다',
										buttons: [{text: '확인', itemId:'ok',ui: 'action'}],
										fn: function(buttonId){
											Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            									url: 'mainpage'
        									}));	// tinglist로 넘어가도록!!
										}
									})
									Ext.getCmp("tingtitle").reset();
									Ext.getCmp("tingcontent").reset();
									Ext.getCmp("tingtheme").reset();
									Ext.getCmp('themeimage').setHidden(true);
									Ext.getCmp("tingdate").reset();
									Ext.getCmp("tingampm").reset();
									Ext.getCmp("tinghour").reset();
									Ext.getCmp("tingminute").reset();
								}
							})
						}
						catch(e){
		 					Ext.Msg.alert("","로그인이 필요합니다");
		 				}
		 			}
 				}]
 			}]
 		}
});

Ext.define("Triends.Model.Userinfo",{
	extend: "Ext.data.Model",
	config: {
		fields: [
			"ID", "Name", "Email", "Age", "Gender", "Introduction", "Cacao"
		]
	}
});

var UserStore = Ext.create("Ext.data.Store",{
	model: "Triends.Model.Userinfo",
	id: 'UserStore',
	proxy: {
		type: "jsonp",
		callbackKey: 'callback',
		url: "http://itscreater.cafe24.com/Triends/Userinfo.jsp"
	}
});

Ext.define('Triends.view.Userinfo', {
 	extend: 'Ext.Panel',
 	requires: ['Triends.view.Login'],
 	id: 'userinfo',
 	xtype: 'userinfo',
	config: {
		style: 'position:relative',
 		layout: 'vbox',
 		fullscreen: true,
 		showAnimation: 'slideIn',
 		scrollable: true,
 		items: [{
 			xtype: 'panel',
 			layout: 'hbox',
	 		minHeight: 150,
 			style: {'padding':'15px', 'border-bottom':'1px #CBCAC7 solid'},
 			items: [
 			{
 				xtype: 'panel',
 				flex: 1,
 				items:[{
 					xtype: 'panel',
 					style: {'left':'50%', 'margin-left':'-50px', 'padding-top':'10px'},
					id: 'userimg',
					width: 100,
					height: 100
 				}]
 			},
 			{
 				xtype: 'panel',
 				flex: 1,
 				layout: 'vbox',
 				items:[{
 					xtype: 'dataview',
 					flex: 1,
 					store: UserStore,
 					margin: '5px',
 					scrollable: false,
 					itemTpl: "<div align='center'><b><font size='4'>{Name}</font></b></div>"
 				},
 				{
 					xtype: 'panel',
 					flex:1,
 					layout: 'hbox',
 					style: 'margin-top:10px;margin-bottom:-10px',
 					items: [
 						{
	 						xtype: 'panel',
		 					style: 'left:50%; margin-left:-75px;padding-left:5px',
	 						width: '150px',
	 						layout: 'hbox',
	 						items: [
			 					{
			 						xtype: 'image',
			 						style: 'margin-left:3px',
			 						src: 'resource/images/cacao.png',
			 						width: 24,
			 						height: 24
			 					},
			 					{
				 					xtype: 'dataview',
				 					store: UserStore,
				 					style: 'margin-left: 15px',
				 					scrollable: false,
				 					itemTpl: "<div align='center'><font size='3'>{Cacao}</font></div>"
			 					}
 							]
 					}]
 				},
 				{
 					xtype: 'panel',
 					flex:1,
 					items: [{
 						xtype: 'button',
 						width: '100px',
 						style: 'border: 2px outset',
		 				id: 'msgboxbtn',
		 				ui: 'small',
		 				text: 'My Message',
		 				width: 150,
		    		   	iconCls: 'mail',
		    	 	   	iconMask: true,
	 					centered: true,
		   			   	handler: function() {
		   			   		var userid = Ext.getStore('UserStore').getAt(0).data.ID;
    						var msgStore = Ext.getStore('msgstore');
            				msgStore.getProxy().setExtraParams({id: userid});
            				msgStore.load({
            					callback: function() {
									Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            							url: 'mainpage/account/mymsg'
	        						}));	
            					}
            				});
            			}	
 					}]
 				}
 				]
 			}]
 		},
 		{
 			xtype: 'panel',
 			layout: 'vbox',
 			style: {'padding':'15px', 'border-bottom':'1px #CBCAC7 solid'},
 			minHeight: 150,
 			items: [
 				{
					xtype: 'panel',
					style: 'margin-bottom:10px',
					html: "<p style='margin-left:5px'><font size='4'><b>Introduction</b></font></p>"
				},
				{
					xtype: 'dataview',
					scrollable: false,
					store: UserStore,
					itemTpl:"&nbsp;<font size='3'>{Introduction}</font>"
				}
 			]
 		},
		{
				xtype: 'usertinglist'
		},
		{
				xtype: 'panel',
				layout: 'hbox',
				style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
				height: 50,
				items: [
				{
					xtype: 'panel',
					flex: 1,
					items:[{
						xtype: 'button',
		 				text: 'Modify',
		 				style: 'border: 2px outset',
		 				
		 				width: '100%',
		 				handler: function() {
		 					var cacao = Ext.getStore('UserStore').getAt(0).data.Cacao;
		 					var introduction = Ext.getStore('UserStore').getAt(0).data.Introduction;
		 					var usercacao = Ext.getCmp('usercacao');
		 					var userintroduction = Ext.getCmp('userintroduction');
		 					usercacao.setValue(cacao);
		 					
		 					if (introduction != null){
			 					if (introduction.match("<br>") != null || introduction.match("&nbsp;") != null){
									introduction = introduction.replace(/&nbsp;/gi, " "); /*/gi를 써서 전체 문자열을 바꿔준다 */
									introduction = introduction.replace(/<br>/gi, "\n");
								}
		 					}
		 					userintroduction.setValue(introduction);
		 					Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            					url: 'mainpage/account/infomodify'
        					}));
		 				}
					}]
				},
				{
					xtype: 'panel',
					flex: 1,
					items: [{
						xtype: 'button',
						width: '100%',
						style: 'border: 2px outset',
						text: 'Logout',
						handler: function(){
							Ext.Msg.show({
								message: '로그아웃 하시겠습니까?',
								width: 300,
								buttons:  [{
			   						id: 'ok',
			   						text: 'Ok',
			   						ui: 'action'
			   					},
			   					{	
			   						id: 'cancel',
			   						text: 'Cancel'
			   					}],
			   					fn: function(buttonId){
			   						if (buttonId == 'Ok') {
			   							var userid = Ext.getStore('UserStore').getAt(0).data.ID;
										FB.logout();  
										window.GCM.unregister(GCM_Success, GCM_Fail);
										Ext.data.JsonP.request({
    										url: 'http://itscreater.cafe24.com/Triends/gcmdelete.jsp',
    										params: {id: userid},
    										callbackKey: 'callback'
    									});
										var login = Ext.create('Triends.view.Login');
										var account = Ext.getCmp('account');
										account.insert(0, login);
										Ext.getStore('UserStore').removeAll();
										Ext.getCmp('titlebar').hide();
										Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
			            					url: 'mainpage'
				        				}));	
			   						} else {
			   							Ext.emptyFn();
			   						}
			   					}
							})
						}
					}]
				}]
		}]
//		{
//			
//	 			xtype: 'dataview',
//	 			minHeight: 200,
//	 			scrollable: false,
//				store:  UserStore,
//				itemTpl: 'Age: {Age} <br>' +
//						 'Gender: {Gender} <br>' +		
//						 'Nationality: {Nationality} <br>' +
//						 'Work: {Work} <br>' +
//						 'Education: {Education} <br>' +
//						 'Love: {Love}',
//				items: [{
	 					
//	 				}	
//				}]	
//			},
		
	}
});

Ext.define('Triends.view.UserinfoModify', {
	extend: 'Ext.Panel',
	xtype: 'infomodify',
	id: 'infomodify',
	config: {
		fullscreen: true,
		scrollable: true,
		padding: 20,
    	items: [
    	{
    		xtype: 'fieldset',
	    	items: [
        	{
    			xtype: 'textfield',
	    		id : 'usercacao',
    	        label: "카카오톡 ID",
    	        labelAlign: 'top',
    	        maxLength: 30
        	},
	    	{
	    		xtype: 'textareafield',
	    		id: 'userintroduction',
	    		label: 'Introduction',
	    		maxRows: 20,
	    		maxLength: 260,
	    		height: 330,
	    		labelAlign: 'top'
	    	}]
    	},
    	{
			xtype: 'button',
			text: 'Modify',
			width: '100%',
			handler: function(){
				var UserStore = Ext.getStore('UserStore');
				var userid = UserStore.getAt(0).data.ID;
				
				var usercacao = Ext.getCmp('usercacao').getValue();
				var userintroduction = Ext.getCmp('userintroduction').getValue();
 				
 				Ext.data.JsonP.request({
   					url: 'http://itscreater.cafe24.com/Triends/UserinfoModify.jsp',
   					params: {
   						id: userid, //localStorage.ID
   						cacao:usercacao,
   						introduction: userintroduction
   					},
          			callbackKey: 'callback',
          			success: function(result) {
         				var UserStore = Ext.getStore('UserStore');
         				UserStore.getProxy().setExtraParams({id: userid});
            			UserStore.load({
            				callback: function() {
            					Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
            						url: 'mainpage'
        						}));
            				}
            			});
           			}
     	 		});
			}
    	}]
	}
});

Ext.define("Triends.UserTinglist",{
	extend: "Ext.data.Model",
	config: {
		fields: ["NUMBER", "ID", "HOST", "TITLE", "THEME", "LAT", "LNG", "CONTENT", "STARTDATE", "STARTTIME", "Date", "Time"]
	}
});


var userHOSTtingStore = Ext.create("Ext.data.Store",{
	model: "Triends.UserTinglist",
	id: 'userHOSTtingstore',
	proxy: {
		type: "jsonp",
		callbackKey: 'callback',
		url: "http://itscreater.cafe24.com/Triends/UserHostTing.jsp"
	},
	sorters: [
		{
			property: 'STARTDATE',
			direction: 'ASC'
		},
		{
			property: 'STARTTIME',
			direction: 'ASC'
		}
	]
});

var userATTENDtingStore = Ext.create("Ext.data.Store",{
	model: "Triends.UserTinglist",
	id: 'userATTENDtingstore',
	proxy: {
		type: "jsonp",
		callbackKey: 'callback',
		url: "http://itscreater.cafe24.com/Triends/UserAttendTing.jsp"
	},
	sorters: [
		{
			property: 'STARTDATE',
			direction: 'ASC'
		},
		{
			property: 'STARTTIME',
			direction: 'ASC'
		}
	]
});

Ext.define('Triends.view.UserTinglist', {
	extend: 'Ext.Panel',
	id: 'usertinglist',
	xtype: 'usertinglist',
	config: {
		layout: 'vbox',
		items: [
			{
				xtype: 'panel',
		    	style: {'margin':'10px'} ,
		    	html: "<p style='margin-left:10px'><font size='4'><b>Hosting</b></font></p>"
			},
			{
				xtype: 'panel',
				style: {'margin':'10px'},
				minHeight: 70,
				items: [{
						xtype: 'list',
						scrollable: false,
						store: userHOSTtingStore,
						pressedCls: "x-item-selected",
						selectedCls: "",
						pressedDelay: 50,
						style: 'background:white',
						itemTpl:"<table>"+
										"<tr>" +
											"<td rowspan='2' align='center' valign='center' width=50 style='word-break:break-all'><img src='resource/images/{THEME}.png' width='48px' height='48px'></td>" +
											"<td valign='center'><p style='margin-left:20px'><font size='4'>{TITLE}</font></p></td>" +
										 "</tr>" +
										"<tr>" +
											"<td valign='center'><p style='margin-left:20px'><font size='2'>{STARTDATE}&nbsp;&nbsp;&nbsp;{STARTTIME}</font></p></td>" +
										"</tr>"+
									"</table>",
			//			useComponents: true,
			//			defaultType: 'UserTingItem',
						listeners: {
							itemtap: function(list, index, target, model, e, eOpts) {
								var tingnum = model.data.NUMBER;
								openTinginfo(model, tingnum)
								}
						}		
					}]
			},
			{
				xtype: 'panel',
		    	style: {'margin':'10px'} ,
		    	html: "<p style='margin-left:10px'><font size='4'><b>Attending</b></font></p>"
			},
			{
				xtype: 'panel',
				style: {'margin':'10px'},
				items: [{
					xtype: 'list',
					minHeight: 70,
					scrollable: false,
					style: 'background:white',
					pressedCls: "x-item-selected",
					selectedCls: "",
					store: userATTENDtingStore,
					itemTpl:"<table>"+
								"<tr>" +
									"<td rowspan='2' align='center' valign='center' width=50 style='word-break:break-all'><img src='resource/images/{THEME}.png' width='48px' height='48px'></td>" +
									"<td valign='center'><p style='margin-left:20px'><font size='4'>{TITLE}</font></p></td>" +
								 "</tr>" +
								"<tr>" +
									"<td valign='center'><p style='margin-left:20px'><font size='2'>{STARTDATE}&nbsp;&nbsp;&nbsp;{STARTTIME}</font></p></td>" +
								"</tr>"+
							"</table>",
		//			useComponents: true,
		//			defaultType: 'UserTingItem',
					listeners:{
						itemtap: function(dataview, index, target, model, e, eOpts) {
							var tingnum = model.data.NUMBER;
							openTinginfo(model, tingnum)
						}
					}	
				}]
		}]
	}
});
	
//Ext.define('UserTingItem', {
//	extend: 'Ext.dataview.component.DataItem',
//    xtype: 'UserTingItem',
//	config: {
//		items: [{
//			xtype: 'panel',
//			tpl: '{TITLE}<br>{STARTDATE} {STARTTIME}'
//		}]
//    }
//});

function fireClick(node){
	if ( document.createEvent ) {
		var evt = document.createEvent('MouseEvents');
		evt.initEvent('click', false, true);
		node.dispatchEvent(evt);	
	} else if( document.createEventObject ) {
		node.fireEvent('onclick') ;	
	} else if (typeof node.onclick == 'function' ) {
		node.onclick();	
	}
} 
 
 Ext.define('Triends.view.VersionPage', {
 	extend: 'Ext.Panel',
 	xtype: 'versionpage',
 	id: 'versionpage',
 	alias: 'versionpage',
 	config: {
 		fullscreen: true,
 		scrollable: false,
 		style: 'background:white',
 		layout: 'vbox',
 		width: '100%',
 		height: '100%',
 		items: [
 		{
	   		xtype: 'panel',
	   		docked: 'top',
	   		style: {'padding-top':'3px','padding-left':'27px','background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#BEBBBB))'},
	   		html: '<b>Version</b>'
	   	},
 		{
 			xtype: 'panel',
 			flex:4,
 			items: [{
 				xtype: 'panel',
 				style: 'left:50%; margin-left:-90px;padding-top:30px',
 				width: 180,
 				height: 90,
 				html: '<img src="resource/images/version.png" width="180" height="90">'
 			}]
 		},
 		{
 			xtype: 'panel',
 			flex:2,
 			html: '<p align="center"><font size="2">현재 버전</font></p><p align="center"><font size="6">1.0 beta</font></p>'
 		},
 		{
 			xtype: 'panel',
 			flex:2,
 			html: '<p align="center"><font size="2" color="#FFCC00">최신 버전</font></p><p align="center"><font size="6" color="#FFCC00">1.0 beta</font></p>'
 		},
 		{
 			xtype: 'panel',
 			layout: 'hbox',
 			width: '100%',
 			style: 'margin-top: 20px',
 			flex:2,
 			items: [{
 				xtype: 'panel',
 				flex: 1,
	 			html: "<p align='center'><a id='useragreement' href='http://itscreater.cafe24.com/Triends/UserAgreement.html'><font size='3'><u>이용약관</u></font></a>",
	 			listeners: {
					tap: {
						element: 'element',
						fn: function() {
							var ua = document.getElementById('useragreement');
							fireClick(ua);
						}
					}
				}
 			},
 			{
 				xtype: 'panel',
 				flex: 1,
 				html: "<a id='privacypolicy' href='http://itscreater.cafe24.com/Triends/PrivacyPolicy.html'><font size='3'>&nbsp;&nbsp;&nbsp;&nbsp;<u>개인정보취급방침</u></font></a>",
 				listeners: {
					tap: {
						element: 'element',
						fn: function() {
							var pp = document.getElementById('privacypolicy');
							fireClick(pp);
						}
					}
				}
 			}]
 		},
 		{
 			xtype: 'panel',
 			flex:1,
 			html: '<p align="center"><font size="2">ⓒ2012 S.U.D, Inc.</font></p>'
 		}]
 	}
 });

 Ext.Loader.setPath({'Ext' : '.'}, {'Triends' : './app/view'});
Ext.application({
	name: 'Triends',
	requires: ['Ext.Map', 'Ext.Button', 'Ext.Panel', 'Ext.app.Action', 
				'Ext.data.Model', 'Ext.data.Store', 'Triends.view.MainPage', 'Ext.dataview.*'],
	controllers: ['Controller'],
	views: ['MainPage', 'Tinglist', 'Tinginfo', 'AttendeeList',  
			'TingComment', 'Sendmessage', 'TingOpen', 'TingModify',
			'PostNormalList', 'PostingNormal', 'Postinfo', 'PostNormalComment', 'PostNormalModify',  
			'Othersinfo', 'OtherTinglist',
			'Login', 'Userinfo', 'UserTinglist', 'UserinfoModify', 'Join', 'Mymessage', 'Mymessageinfo', 'AgreementConfirm', 
			'Settings', 'VersionPage', 'Noticelist', 'Noticeinfo', 'HelpPage', 'QuestionPage', 'PushPage'],
    launch: function() {
    	Ext.create('mainpage');
				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {url: 'mainpage'}));
    	document.addEventListener('deviceready', function() {
    		try {
    			FB.init({ appId: "221973064597313", nativeInterface: CDV.FB, useCachedDialogs: false });
    			
//				FB.getLoginStatus(function(response) {
//            		console.log(response.status);
//  					if (response.status == 'connected') {
//				    	// the user is logged in and has authenticated your
//				    	// app, and response.authResponse supplies
//					    // the user's ID, a valid access token, a signed
//					    // request, and the time the access token 
//					    // and signed request each expire
////    					var uid = response.authResponse.userID;
//    					var accessToken = response.authResponse.accessToken;
//  						FB.Event.subscribe('auth.login', autologin(accessToken));
//  					}
// 				});
            	
            	
            	
            	document.addEventListener("backbutton", Ext.bind(onBackKeyDown, Triends), true);
   				
   				
            	function onBackKeyDown(e) {
            		e.preventDefault();
            		
            		if (Ext.typeOf(Ext.Viewport.child('mask')) == 'object') {
            			Ext.Viewport.child('mask').fireEvent('tap')
            		} else if ( Triends.app.getHistory().getToken() == 'mainpage') {
            			Ext.Msg.show({
  							title: '',
  							message: 'Triends를 종료하시겠습니까?',
   		        			width: 300,
   							buttons:  [{
   								id: 'ok',
   								text: 'Ok',
   								ui: 'action'
   							},
   							{	
   								id: 'cancel',
   								text: 'Cancel'
   							}],   					
   							fn: function(buttonId) {
    	   						if (buttonId == 'Ok') {
	       							navigator.app.exitApp();
								} else if (buttonId == 'Cancel') {
       								Ext.emptyFn
       							}
   							}
						});
            		} else {
            			navigator.app.backHistory();
            		}           		
            	}
        	} catch (e) {
            	alert(e);
 	    	}
    	}, false); 
    }
});

function autologin(accessToken) {
	FB.api('/me?access_token='+accessToken, function(response) {
  							console.log(response.id);
						Ext.data.JsonP.request({
            				url: 'http://itscreater.cafe24.com/Triends/Login.jsp',
            				params: {
            					id:response.id,
            					name:response.name,
            					email:response.email, 
            					age:response.age,
            					gender:response.gender
            					// Userlist에서 사용할 부분
            					//userlat:userlat,
            					//userlng:userlng
            				},
            				callbackKey: 'callback',
            				success: function(result) {
            					if(result.message == "Good") {
							    	var UserStore = Ext.getStore('UserStore');
							    	UserStore.getProxy().setExtraParams({id: response.id});
            						UserStore.load({
				        				callback: function(records, operation, success) {
				        					var userid = UserStore.getAt(0).data.ID;
				        					
				        					window.GCM.register("157631774206", "GCM_Event", GCM_Success, GCM_Fail );
        									var userimg = Ext.getCmp('userimg');
        									userimg.setHtml("<img src='https://graph.facebook.com/"+userid+"/picture'>");
			        					
        									var userHOSTtingStore = Ext.getStore('userHOSTtingstore');
											userHOSTtingStore.getProxy().setExtraParams({id: userid});
											userHOSTtingStore.load({
												callback: function() {
													var userATTENDtingStore = Ext.getStore('userATTENDtingstore');		
													userATTENDtingStore.getProxy().setExtraParams({id: userid});
													userATTENDtingStore.load({
														callback: function() {
																var titlebar = Ext.getCmp('titlebar');
																	titlebar.show();
            													var accountcmp = Ext.getCmp('account');
        		        											accountcmp.setActiveItem(1);
        		        										var logincmp = Ext.getCmp('login');
        		        											logincmp.destroy();
														}
													});
												}
											});
				        				}
            						});
            					} else if (result.message == "Bad") {
            						FB.logout();
            						Ext.Msg.alert('알림', '가입되어있지 않습니다', Ext.emptyFn);
            					}
            				},
            				failure: function(result) {
            					Ext.Viewport.setMasked(false);
            					Ext.Msg.alert('알림', '서버 실행 오류:', Ext.emptyFn);
            				}
            			});	
					});	
}


    				
    				
    			
    				
    				
    			
				
		 				